Async Techniques and Examples in Python Transcripts
Chapter: async and await with asyncio
Lecture: Performance improvements of producer consumer with asyncio

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's take a moment and just appreciate the performance improvements that we got. And there's two metrics on which I want to measure this.
0:07 One is overall time taken for some amount of work to be done and the other is what is the average latency? How long does it take for the consumer
0:16 to get the data that the producer produced? So, here's the synchronous version a subset of it, we generate all the data
0:24 and then we process all the data. And you can see the overall time it took was about 30 seconds and the average latency is about 15.
0:32 The best we ever got was 10 seconds that was for the very last one that we processed. And if we did the example where we had
0:39 two of them, it would be even worse. So, this is okay, but it's not great. And we saw that with asyncio we can dramatically improve things.
0:49 So over here, we don't have all the work being done in terms of producing and then all the consumption we have them interleaved because
0:56 there's all these points where the producer's waiting on certain things the consumer's waiting. So that time can be more productively spent
1:03 letting the other parts run. So we're generating some data we're processing it, generating a few more processing a few more, things like that.
1:10 Now, this one took a total of 21 seconds that's about 9-10 seconds better. Good, not rock your world better but certainly an improvement.
1:20 But, the latency. The latency is so much better. Look at those numbers. So, it's 8.5 seconds faster and 60 times less latency.
1:32 I think that's amazing. I think this is really, really great and it was, as you saw, super easy to accomplish. So, anytime you're waiting on I/O
1:40 files, database, webservice calls things like that, this is really, really a great technique.

Talk Python's Mastodon Michael Kennedy's Mastodon