Async Techniques and Examples in Python Transcripts
Chapter: Why async?
Lecture: Async for computational speed

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's begin our exploration of async by taking
0:02 a really high-level view, we're going to look
0:05 at the overall async landscape, some of the particulars
0:09 about working with async in concurrent programming
0:11 in Python, and the two main reasons that you care
0:14 about asynchronous programming.
0:16 In this first video we're going to focus on async for speed or
0:20 for performance, the other main reason you might care
0:23 about asynchronous programming or concurrent code would be
0:26 for scalability, doing more at once.
0:29 Right now we're going to focus on doing things faster
0:32 for an individual series of computations.
0:35 Later we're going to talk about scalability
0:37 say for web apps and things like that.
0:39 Let's look at some really interesting trends that have
0:43 happened across CPUs in the last 10 years or so, 15 years.
0:47 So here's a really great presentation by Jeffrey Funk
0:50 over on SlideShare and I put the URL at the bottom
0:52 you can look through the whole thing, you can see there's
0:54 172 slides, but here I am pulling up one graphic that
0:57 he highlights, because it's really, really interesting.
1:01 See that very top line, that red line, that says
1:03 transistors in the thousands, that is Moore's Law.
1:07 Moore's Law said the number of transistors in a CPU
1:11 will double every 18 months and that is surprisingly
1:15 still accurate; look at that, from 1975 to 2015
1:19 extrapolate a little bit, but still basically doubling
1:23 just as they said.
1:25 However people have often, at least in the early days
1:28 thought of Moore's Law more as a performance thing
1:31 as the transistors doubled, here you can see
1:33 the green line "clock speed" and the blue line "single threaded
1:37 performance" very much follow along with Moore's Law.
1:40 So we've thought about Moore's Law means computers get
1:44 twice as fast every 18 months and that was true more or less
1:48 for a while, but notice right around 2008, around 2005
1:53 it starts to slow and around 2008 that flattens off and
1:57 maybe even goes down for some of these CPUs and
2:00 the reason is we're getting smaller and smaller and smaller
2:03 circuits on chips down to where they're basically
2:05 at the point of you can't make them any smaller, you can't
2:08 get them much closer both for thermal reasons and
2:12 for pure interference reasons.
2:14 You can notice around 2005 onward, CPUs are not getting
2:19 faster, not really at all. I mean, you think back
2:22 quite a bit and the speed of the CPU I have now is
2:24 I have a really high-end one, it's a little bit faster but
2:28 nothing like what Moore's Law would have predicted.
2:30 So what is the take away?
2:31 What is the important thing about this graphic?
2:34 Why is Moore's Law still effective?
2:37 Why are computers still getting faster, but the CPU and
2:40 clock speed, really performance speed, single-threaded
2:43 performance speed, is not getting faster, if anything
2:45 it might be slowing down a little.
2:47 Well that brings up to the interesting black graph
2:50 at the bottom, for so long this was one core and
2:53 then when we started getting dual-core systems and
2:56 more and more CPUs, so instead of making the individual
3:00 CPU core faster and faster by adding more transistors
3:03 what we're doing is just adding more cores.
3:05 If we want to continue to follow Moore's Law
3:08 if we want to continue to take full advantage of the
3:11 processors that are being created these days
3:14 we have to write multi-threaded code.
3:17 If we write single-threaded code, you can see it's either
3:19 flat, stagnant, or maybe even going down over time.
3:23 So we don't want our code to get slower, we want our code to
3:26 keep up and take full advantage of the CPU it's running on
3:29 and that requires us to write multi-threaded code.
3:32 Turns out Python has some extra challenges, but
3:35 in this course we will learn how to absolutely take
3:38 full advantage of the multi-core systems that
3:40 you're probably running on right now.