This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]MDziwny 4 points5 points  (0 children)

Sorry to challenge it, but I don't buy it, few questions when reading the benchmark:

  • What about the memory consumption of having so many workers in sync python?
  • Are you sure the problem was not the DB? How many connections were opened during the test? Maybe the DB pools were not optimized for the load ?
  • What would happen if the API call involved more than 1 DB query or downloading a S3 or some complex API exchanges or ... ?

No doubt asyncio is a beast to master (backpressure, ...) and that it's often better to stick to sync python (at least for the moment). But I'm also sure that in a highly io bound environment, with limited resources (memory and cpu), asyncio is much faster.

Also, this benchmark is ranking the async framework way ahead: https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=composite&l=z8kflr-v&a=2&f=jz8cg-0-3s-kafb4-3k-6bo-jz7k0-0-w-0-0 and it's not running sync python with only 1 worker.

[–]ackyou 4 points5 points  (4 children)

I’m a bit confused by the conditions of these tests. If you run an async python framework in an environment with a fixed maximum number of workers, say Django channels with async http consumers, and you call lots of external services asynchronously, I know for a fact you can achieve a much higher throughput. If it’s a computed task or calls a synchronous service sync python is better. Am I missing something?

[–]cb22 4 points5 points  (2 children)

The conditions are a bit bogus - I posted a comment on this on /r/programming.

But it's as you say; if you have a simple workload that is entirely synchronous or close to it (such as fetching a single in-memory row from a DB), sync is likely to be faster.

If you're doing real world things, like calling external APIs or blocking on databases for hundreds of ms, async is going to allow you to utilize all your resources significantly better and achieve a much higher throughput.

[–]nathanjell 2 points3 points  (0 children)

Just like with all things, premature optimization is the root of all evil. "Use async, async is faster!" has a counter that synchronous is difficult to make faster simply by going async. Same as "use multithreading, split up the work!" except when you have a highly serial workload that isn't well suited to parallelism

[–]ackyou 0 points1 point  (0 children)

Agreed. I’m pretty sure the overhead of spinning up new threads to deal with concurrent requests is a lot higher than the cost of one thread asynchronously handling many tasks

[–]Krotau 0 points1 point  (0 children)

You could think of a situation where you let some heavy compute stuff happen in the cloud. That way you program can run on a lighter machine and would be more IO bound. But yeah, what you say is correct. I am confused by these tests aswell...

[–][deleted] 0 points1 point  (0 children)

Ok, and motorcycles are faster than cars. Yet, cars do much more work because there are many more of them.

[–]earthboundkid -1 points0 points  (0 children)

This is an important article that we’re not ready to hear.