Reputation: 3490
I have an app to send a bunch of HTTP requests. First, I use eventlet and requests to implement it. But the performance is too low. Hence, I expected to speed it up using multi-process. A thing need to know is that the server will takes about 200ms to handle a single request (no including network transfer).
However, the multi-process is slower than the original version. I feel so amazed about this result! Why?
The code as following shown, I used timeit to measure time.
import eventlet
eventlet.monkey_patch(all=False, socket=True)
import requests
URL = 'http://....'
def send():
pile = eventlet.GreenPile(20)
for x in xrange(100):
pile.spawn(requests.get, URL)
for x in pile:
pass
import multiprocessing
def main():
procs = [multiprocessing.Process(target=send) for _ in range(3)]
for p in procs:
p.start()
for p in procs:
p.join()
import timeit
if __name__ == '__main__':
print timeit.timeit(main, number=1)
Upvotes: 1
Views: 643
Reputation: 5577
TL;DR: not enough information. By pure speculation, the server is the limiting factor (which may be caused by intentional artificial limits or resource starvation), so by adding more concurrent requests you are making each slower on average.
Here's one way to reason about this: you have limited amount of resources on both client and server: CPU cycles per time, memory accesses per time, memory size, network bandwidth. OS and eventlet make reasonable use of these resources. Such that you can do estimates on how much resources it takes to make a single request and software will scale it out in a reasonable pattern (that is close to linear). To benefit from multiprocessing would require your client process makes single CPU unit 100% busy. And specifically requests
library is known to be good at wasting hardware resources, it incurs the most CPU overhead of all I tried (httplib, httplib2, urllib). But you have to make really lots (thousands) of concurrent requests or have really bad/busy CPU to make it bottleneck.
Exact answer requires information:
Answering these questions will provide you with excellent intuition on what's going on inside and between your client/server.
Relevant Github issue: https://github.com/eventlet/eventlet/issues/195
Upvotes: 1