- Podcasts
- Python Bytes
- #12 Expanding your Python mental model and serving millions of requests per second with Python
#12 Expanding your Python mental model and serving millions of requests per second with Python
Python Bytes
- February 7, 2017
- 19 min
- Episode 12
About this episodeTopics covered in this episode: Why Learn Python? Here Are 8 Data-Driven Reasons by Dan Bader A million requests per second with Python…
- Why Learn Python? Here Are 8 Data-Driven Reasons by Dan Bader
- A million requests per second with Python
- Python Top 10 Articles for the Past Year (v.2017)
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#12 Expanding your Python mental model and serving millions of requests per second with Python
This is Python Bytes. Python headlines and news delivered directly to your earbuds. It's episode 12 recorded February 6th, 2016. This is Michael Kennedy, one of your hosts, here with my co-host Brian Okken. Hey Brian, how's it going, man? It's going really good. Yeah, I'm super excited to talk about what we got to cover today.
But I also want to say thank you. I want to say thank you to Rollbar because they're sponsoring this episode. And I'll tell you more about their cool stuff that they do later. Let's start out about with the way that you think about programming. Because learning to program is somewhat learning the syntax, but it's also just learning the mental models of what programming means, right?
Yeah, and I did realize that when you think about Python, the problems and problem solving is different in Python than in other languages. Just because of the idiosyncrasies of the language and how people tend to do things. And a couple of good articles that I stumbled across. Actually, I think one of them is a...
Anyway, so there's Python functions aren't what you think. And this is on a site called Powerful Python. And it's a short little article just talking about that functions are really just objects that happen to have a name. That's the name of the function that you gave it. And they're really that much different than giving a variable the value of five.
You just give a variable a value of a function. It does change the way you... If you can think about functions that way, you can change the way you do some things. You know, not surprisingly, I think it really enables functional programming type of metaphors. Just the whole concept of treating functions as first class objects, right?
Functions are like variables or like classes or like whatever. And I think that's really interesting. It's really super important for things like lambdas and closures that we can treat functions this way. But even normal functions are basically the same thing, right? Yeah, and that you can just throw one in a data structure and use it later.
But it's actually a Jupyter notebook that talks about the relationship between objects, classes, and meta classes. And again, it's a similar thing of not just functions are objects, but even classes themselves are objects. Right. Right. And their classes are meta classes, right? Which is, it's very crazy.
Yeah, it definitely is a mental shift, especially the meta programming. And that's something I could learn more about personally as well. Yeah, me too. And I haven't really made use of it a lot, but it's kind of one of those things of if you can think about the whole thing and how it fits together in just kind of a little mental overview, I think it helps.
Yeah, excellent. All right, number two, the one that I chose is an article by a friend of the show, Dan Bader. And his article he wrote, which I helped him a little bit with, you'll see at the very end, is called Why Learn Python? Here are eight data-driven reasons. And people send me messages and say, hey, Michael, I'm thinking about changing careers or aspects of my career.
Maybe I'm a Java developer and I'm considering learning Python. Is it worth it? And you'll see from this article, the answer is yes, yes, and absolutely yes. Python is the second most popular language in the world, according to the popularity of Programming Language Index. It's one of the hottest job skills to have, according to Dice.
And Dan lays out eight really well-researched reasons why this is the case, basically to support these trends. So, you know, it says you can learn pretty much anything with Python. It's widely used by data scientists. Python pays well. In fact, it's number two only to Ruby developers, according to Guru.
But it has many more job openings than Ruby does. And it's, on average, above all the other developer salaries if you're looking at the U.S. So, for example, they say Indeed says the average Python developer in the U.S. across all the regions, they're thinking that's something between $103,000 and $116,000 a year, which is amazing, really.
It's totally bizarre. I forgot that. I mean, there's like a couple of good Python podcasts around this, at least, right? Yeah. You know, that's one of the good reasons to learn Python. Yeah, so we'll add one in there, that's for sure. It definitely helps you. And so there's demand is growing for Python developers.
It saves you time. It's beginner-friendly, but you don't top out really quickly, right? Like, it can be an advanced language as well. All the big companies are using it. So if you want to get a job somewhere cool like YouTube or IBM or Mozilla or Quora or Instagram, all these companies are making major use of Python.
So this could be your ticket there. And finally, Python has a great ecosystem. Yeah, and one of the great things about articles like this are we're preaching to the choir, of course, but a lot of people get those questions of like, well, why should I learn Python? And all I usually have is it's fun and cool and why not?
So these are better reasons. Yeah, this is really, it's a really great article. And of course, we're linking to it. I think it's not, I mean, it's great to be preaching to the choir, but it's also interesting to provide this as fuel for people having these debates. Maybe they're working on a team and they're like, well, what technology should we choose for our next topic, our next project or something?
So there's, and cool last name too. I think I'm going to try this. Kevin Ndungu, I think. Ndungu? Anyway. Testing Python Applications with pytest. And it's a good introduction article to try to not scare people off too bad about some of the advanced features. But after getting, jumping into it a little bit, he shows how easy it is, of course, to write tests.
But then also takes a look at one of the common things that happens is you grow a whole bunch of tests. And then you want to refactor them. And there's a little bit about refactoring your tests by using fixtures and pulling out some of the common starting state. And then he jumps into a couple of the nice, one of the nice features of pytest, of course, is the parameters.
And then you're going to have a lot of the standardization of easily being able to throw multiple data sets at an individual test function. And that was demonstrated pretty cleanly. I like that. Nice. Good job, Kevin. And I like the article. Yeah, I really like the let's treat test code as production code.
Like, why is this not a function or some other thing that you can use throughout your test, right? Yeah. Yeah, definitely. Speaking of production, you don't want errors in your production, do you? No, of course not. No, not too much. One of the first steps in solving errors in production is knowing about them.
And that's where Rollbar comes from. So Rollbar is supporting the show this week. Thank you, Rollbar. And I've used Rollbar for a long time on the website that delivers Python bytes and my training courses and all those things. And I would say at least five times Rollbar has saved me from some seriously bad choices that I've made.
And of course, Rollbar sent me a message, popped up on my phone immediately and said, error in production. Here's the exact details of what you need to fix. And I was like, ah, crap. You know, five minutes later, though, it was fixed. So thanks, Rollbar, for helping me out then. And thanks for sponsoring the show.
Awesome. It was a special offer for listeners. And I'll put that link in the show notes right at the top. Speaking of production, we would all like our code to run a little bit faster. And I feel like we're in this cool place with Python, especially Python versus legacy Python. Like Python 5, 3.6, and 3.7, the one that's coming, have really been focused on performance.
And so there's a, you know, we talked about a web framework called SANIC that was based on aiohttp, which is an async pipeline for web processing. Well, here comes another one. And this one, it turns out, if the benchmarks are to be believed, is dramatically faster than even SANIC and lots of other things out there like Go.
It has like 2,600 stars on GitHub. And the title of the article introducing it was Handling a Million Requests Per Second with Python. Yeah. I think that's on one server. So that's crazy. It is crazy fast. It's pretty exciting. If you read this article that we're linking to, the guy who built it, he's doing a crazy amount of careful thought and low, low, low level OS type of optimization.
So just to give you a sense, most of this is written in C, although he's thinking of rewriting it in Rust. He talks a bit about that and says, look, I'm going to call it Jepronto. I'm going with that one. Jepronto tries to delay the creation of Python counterparts of its internal structures until explicitly asked.
So, for example, like normally when a request come in, like the request object would be populated with like headers. Well, this framework won't actually create the headers dictionary unless you try to access it. It gives you only what you need at many, many levels and has some really cool low level optimizations around pipelining.
Why isn't it better to be correct? I guess I like to have both. And I think it would be, I think I'm intrigued by other people trying to get performance up. And I think it's, to me, it's important because I would hate to have somebody say, oh, eventually you're going to scale out of Python and need to switch over to go.
Exactly. That's the primary thing. I think, and even if you're not going to scale out, if you start to hear lots of major companies saying, we're all abandoning Python because they won't run our workloads. Even if that's not the situation you're in, it starts to like cast a shadow over the general ecosystem.
Right. Whereas if you say, no, no, look at these amazing things that are being done with Python on the web, your stuff is going to be way lower traffic and load than that. Surely this will work for you as well, right? Yeah. So I think it's really interesting. I mean, to be honest, Pyramid plus uWSGI plus NGINX just straight up is way fast enough for what I'm doing, even with a couple million ACP requests a month.
But it's super cool to see that it's sort of expanding the upper bound. And I think that's going to have some great stories down the road. Yeah, definitely. So the next topic we've got is a good news thing that came out, was just announced today. The Rethink, and I'm not sure if you had RethinkDB on.
I did. I had him on my show. I can't remember the number. I think it's in the 60s on Talk Python TV. We talked about RethinkDB and the company behind it. Yeah, and I think I've heard about it because of Talk Python. But it was really intriguing to me. And I like the idea of somebody just from the ground up rethinking how databases work with live data and real-time data.
But in September of last year, the company shut down. And I was curious, like everybody else was, is what's going to happen to RethinkDB? But I guess somebody called Cloud Native Computing Foundation, they made an announcement that they purchased the rights to the source code and contributed to the Linux Foundation.
And it's changing the licensing as well to the Apache license version 2. And everybody can continue using it now and will be able to have this project live on. That's really cool. So RethinkDB is supposed to be like a real-time, it's like a document database that is a real-time database for your server.
So it's definitely got some interesting components. And I believe all the team that worked there has made their way over to Stripe. I'm pretty sure that's what's happening. So everybody who used to work at Rethink has kind of moved over to Stripe. And that's really cool that they had a soft landing somewhere.
And it's great to see the Linux Foundation taking up this project and keeping it going. And I guess there were some companies that are relying on it and wanted to somehow donate to try to keep it going. And there wasn't a way to do that at first. And now there is, and they've got, especially under the Linux Foundation, and Stripe has put together $25,000 in matching funds to match other donations.
But what they did is they said, how many articles? They had some crazy number of articles that for the past year, we've ranked nearly 10,000 Python articles. And we picked the top 10 stories with a 0.1% chance that will help you advance your career in Python. Oh, nice criteria. Yeah, it's really nice, right?
Data mining in Python. Python FAQ. Why should I use Python 3? By Eve. Remember the whole Zed Shaw. Python 2 is going to live forever. No Python 3. This guy wrote the beautiful rebuttal to that article. So this article is also by him. Introduction to Stock Market Analysis, NumPy Tutorial, and Build Your First Python and Django app.
So I like this pick for a couple of reasons. One is it's just cool to have some really nice reading. And this is kind of a cool app, this MyBridge thing. I've just started playing with it. But I think it gives you a pretty interesting view into the Python space. People ask, what can you do with Python?
So even though that's our six items, I actually have one more for you. Last week, we talked about Red Hat distribution, Red Hat Enterprise Linux, and how people are having trouble using Python 3 because they keep sending this message going, I can't use Python 3. Well, a friend of the show, Chip Warden, actually added a comment.
Yeah. So that's cool. So that's definitely going to be in the show notes. All right. Well, that's one more reason to switch to Python 3, right? Definitely. And I can't believe we're done already. Going so fast. I know. Well, I think we're going to have to scour the internet for more cool Python stuff for next week.
What do you say? Yes. And I want to encourage anybody to help us out by sending us what you think we ought to cover next week. Yeah. We don't always cover everything people send, but if it matches up, we definitely try to cover it. So please help us out. If you know something like Chip did here that we didn't cover, send it our way.
