4 ms·
This is just a fundamental misunderstanding of what concurrency is. I do not see why it requires a benchmark. Concurrency is many things at once. That's it. A
by ohyes 6y ago
This is just a fundamental misunderstanding of what concurrency is. I do not see why it requires a benchmark.
Concurrency is many things at once. That's it.
Async frameworks end up with better concurrency properties because you're not paying the memory and context switching overhead of an entire 'thread' for each thing that you are trying to do at the same time. Instead you are paying the (normally cheaper) overhead of what is essentially a co-routine call.
The disadvantage being that you have to manage these context switches yourself, and that they tend to happen more frequently (to maintain the illusion that we are doing many things all at the same time on a single cpu). There is no way that an async framework would ever have better straight line performance than a synchronous one, simply because of all of these extra context switches, and that's fine because that's not what it is for.
Imagine I want to have 10,000 requests held open at the same time. Your flask server with 16 workers is going to have a tough time as you don't have enough workers to service that many threads, requests won't get serviced and things will start to time out. Because an async framework multiplexes those workers so that can each individually handle multiple requests at once. Multiplexing in this way costs you something performance wise.
If you were to crank up the concurrency beyond 100 at once (the default in the posted scripts), you would start getting different results.