3 ms·
Do you have empirical evidence for this? Even theoretically, threads can perform better because pythom does infact release the Gil for i/o bound operations and
by devxpy 6y ago
Do you have empirical evidence for this? Even theoretically, threads can perform better because pythom does infact release the Gil for i/o bound operations and also, not blocking an event loop when a cpu bound task is running.
In my experience at least, asyncio was almost always slower than threads, in terms of just raw throughput (as seen from nethogs)
- joshlk 6y agoI do actually - just dug it out: https://imgur.com/a/0uIQW6f https://imgur.com/a/0uIQW6f This was an experiment I did against a very slow API. It's 5 years old and so I was using Python 2.7. The graph shows number of completed requests per second against number of threads. As you can see at first the throughput linearly increases with threads but then plateaus at around 12 threads. I haven't done the same experiment with async-io but it would be quite easy using this package `many-requests`
- devxpy 6y agoHow do you know the bottleneck is python's threads, and not the server or your network? If its the latter, no amount of async programming will improve this graph.