Obviously async is father than non-async for certain workloads. If a program doing something completes in less time, it is “faster.”
There’s nuance to the difference between concurrent and parallel, and situations where concurrency without parallelism provides no speed up (e.g., compute heavy async), but such an obviously click-bait headline is off putting.
ETA: If the claim is that async isn’t faster than threads, or something else specific, sure. But not faster than anything…?
That’s not how async works, if you’re waiting for io then the io is the bottleneck. Async allows you to get more out of your hardware for io bound tasks
Imagine you read data for 100 ms and then do compute for 100 ms. In other words, for each 100ms of data read there is 100 ms to compute.
Imagine you process two blocks.
With blocking, you read for 100 ms. Then you compute for 100 ms. Next you read for 100 ms. Then Compute for 100 ms. Wall clock time? 400 ms.
Now async:
You read 100 ms. You start the compute process, which returns immediately. You then issue the read the next chunk. Python releases the GIL while it does the read. Finally when the first async call is done, the second one can begin as soon as the second read completes.
This example completes in 300 ms. So it is faster than non-async.
Now you are overlapping I/o and compute. The second example will complete in 300 ms instead of 400ms for the first.
Python release the GIL for I/o. So the threads give the exact same speed up as async.
ETA: Your statement is correct when the program execution time is entirely dominated by the i/o.
Async does not help performance when your application is almost all compute or almost all I/o. However, for a more balanced mix, it will allow progress to be made when a blocking program cannot make progress.
This is the difference between concurrency and parallelism.
You don’t need async to do that, you can use threads and may even be able to speed things up if you fork out sub processes because you can do the computations in parallel
Your original claim was that’s not how async works and that async can only help you get more out of your hardware for I/o bound tasks.
I have disproven this claim trough a simple example presented in introductory operating system classes.
Operating systems like Linux, and others, have had async I/o operations for years. The concept is the same even if the operating mechanisms are different. It’s not something unique or specific to python. It’s a different model of concurrency from the threading model.
Now you are moving the goal posts. If you want to debate whether it is the right design to use for the task at hand, that’s a separate issue. But what you originally stated, that that is not how async works, is incorrect. It works as I described… unless you have evidence to the contrary?
6
u/spoonman59 Sep 09 '22
I can’t get past the title. Faster than what?
Obviously async is father than non-async for certain workloads. If a program doing something completes in less time, it is “faster.”
There’s nuance to the difference between concurrent and parallel, and situations where concurrency without parallelism provides no speed up (e.g., compute heavy async), but such an obviously click-bait headline is off putting.
ETA: If the claim is that async isn’t faster than threads, or something else specific, sure. But not faster than anything…?