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
0:01 why you care about asynchronous programming.
0:04 We focus on two core areas.
0:06 One, taking advantage of modern CPUs
0:09 and the other is doing more productive things
0:12 while we're waiting. On the CPU side
0:15 I showed you this graph from Geoffrey Funk's presentation.
0:18 It shows Moore's Law at the top
0:20 but the part that we care about
0:22 if we are not writing in current programs is that blue line.
0:25 In around 2005, that's just flattening off
0:28 and maybe even turning downwards
0:30 for say energy conservation reasons.
0:32 So, the only way to stay with the red line
0:35 and not get sucked down on the blue line
0:38 is to take advantage of concurrency.
0:40 So, you want to follow that black line
0:42 by leveraging the multiple cores.
0:44 We saw that this machine I'm recording on now
0:46 has 12 cores, so, if I write single threaded Python
0:50 I'm getting 8.33% of the capability out.
0:53 So, obviously that's important.
0:54 Now what are the two ways
0:56 that we can actually leverage this?
0:57 Remember, the GIL means threads don't help or work.
1:00 asyncio is single threaded anyway
1:02 so it doesn't help at all
1:04 so it's really down to multiprocessing
1:05 or Cython's C-based solution of no GIL
1:10 to break the Python threads free.
1:14 If you want to take advantage of modern hardware
1:15 you need to write concurrent code
1:17 and it's the two main ways that I just talked about
1:19 that will help you do that in Python.
1:21 Maybe even more common than trying to make a single
1:24 computation go faster is to just do more at the same time.
1:28 This could be your web server
1:29 or you're doing some sort of interaction
1:32 with external systems like your web scraping
1:34 or something to that effect.
1:35 So we saw that with asynchronous programming
1:37 we can take what is a long request
1:39 but mostly a request that is waiting on a database
1:42 waiting on a web service call or combinations thereof
1:45 and turn those into times where we can
1:48 stop working on that request while it's waiting
1:50 and go handle the next one almost instantly
1:52 so we saw that if we're able to leverage asyncio
1:54 in our web frameworks we can do much, much more
1:57 with the same hardware and the same web servers.