Async Techniques and Examples in Python Transcripts
Chapter: Course conclusion and review
Lecture: Review: Why async?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We begin the course by talking about why you care about asynchronous programming. We focus on two core areas. One, taking advantage of modern CPUs
0:10 and the other is doing more productive things while we're waiting. On the CPU side I showed you this graph from Geoffrey Funk's presentation.
0:19 It shows Moore's Law at the top but the part that we care about if we are not writing in current programs is that blue line.
0:26 In around 2005, that's just flattening off and maybe even turning downwards for say energy conservation reasons.
0:33 So, the only way to stay with the red line and not get sucked down on the blue line is to take advantage of concurrency.
0:41 So, you want to follow that black line by leveraging the multiple cores. We saw that this machine I'm recording on now
0:47 has 12 cores, so, if I write single threaded Python I'm getting 8.33% of the capability out. So, obviously that's important. Now what are the two ways
0:57 that we can actually leverage this? Remember, the GIL means threads don't help or work. asyncio is single threaded anyway so it doesn't help at all
1:05 so it's really down to multiprocessing or Cython's C-based solution of no GIL to break the Python threads free.
1:15 If you want to take advantage of modern hardware you need to write concurrent code and it's the two main ways that I just talked about
1:20 that will help you do that in Python. Maybe even more common than trying to make a single computation go faster is to just do more at the same time.
1:29 This could be your web server or you're doing some sort of interaction with external systems like your web scraping or something to that effect.
1:36 So we saw that with asynchronous programming we can take what is a long request but mostly a request that is waiting on a database
1:43 waiting on a web service call or combinations thereof and turn those into times where we can stop working on that request while it's waiting
1:51 and go handle the next one almost instantly so we saw that if we're able to leverage asyncio in our web frameworks we can do much, much more
1:58 with the same hardware and the same web servers.

Talk Python's Mastodon Michael Kennedy's Mastodon