TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Making 1000 HTTP requests per second in Python

31 pointsby jonlucaover 3 years ago

4 comments

ArtTimeInvestorover 3 years ago
For what its worth, this would be the bash equivalent:<p><pre><code> for i in {1..1000} do wget --quiet &quot;somehost&#x2F;$i&quot; -O &quot;$i.html&quot; &amp; done wait </code></pre> Takes 1.8 seconds here. But will obviously depend on the network situation and server. And there probably is something faster than wget.
评论 #29687348 未加载
评论 #29685947 未加载
axiosgunnarover 3 years ago
Or switch to a language more suited for the job and you can add a „k“ to that 1000
评论 #29675035 未加载
评论 #29675924 未加载
anamaxover 3 years ago
I wonder where the time is going. I suspect that something like atop would show that the CPU is idle for much of the time, which suggests that the problem is not Python or even the GIL.<p>If that&#x27;s true, there&#x27;s something ineffective about the way that the requests are being made&#x2F;handled.<p>AFAIK, the author did not try &quot;make a bunch of requests before waiting for answers&quot;. If many of the requests are going to the same server, blasting a bunch of requests down a single socket before waiting for a response should be faster, if only because there&#x27;s only one ssl handshake, even if the remote server doesn&#x27;t pipeline request processing. (I suspect that &quot;too many threads&quot; didn&#x27;t work because that reduced connection reuse.)<p>There&#x27;s a fairly simple monkey patch to http\httpsconnection that enables request pipelining.<p>It might also be useful to use something like epoll to wait for the sockets.
评论 #29679274 未加载
No1over 3 years ago
If anyone is wondering why the threaded implementation was slower<p>&gt; pool = ThreadPool(40)
评论 #29677002 未加载
评论 #29677777 未加载
评论 #29678428 未加载