What is the fastest way to send 100,000 HTTP requests in Python?

前端 未结 16 1208
暖寄归人
暖寄归人 2020-11-22 07:12

I am opening a file which has 100,000 URL\'s. I need to send an HTTP request to each URL and print the status code. I am using Python 2.6, and so far looked at the many con

16条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 07:25

    If you're looking to get the best performance possible, you might want to consider using Asynchronous I/O rather than threads. The overhead associated with thousands of OS threads is non-trivial and the context switching within the Python interpreter adds even more on top of it. Threading will certainly get the job done but I suspect that an asynchronous route will provide better overall performance.

    Specifically, I'd suggest the async web client in the Twisted library (http://www.twistedmatrix.com). It has an admittedly steep learning curve but it quite easy to use once you get a good handle on Twisted's style of asynchronous programming.

    A HowTo on Twisted's asynchronous web client API is available at:

    http://twistedmatrix.com/documents/current/web/howto/client.html

提交回复
热议问题