Python Bytes - #12 Expanding your Python mental model and serving millions of requests per second with Python
Episode Date: February 7, 2017Topics covered in this episode: 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... See the full show notes for this episode on the website at pythonbytes.fm/12
Transcript
Discussion (0)
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 Ocken.
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 episode and I'll tell you more about their cool stuff that they do later.
Let's start out about with like the way that you think about programming because
learning to program is somewhat learning the syntax, but it's also just learning like 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 other language 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, and I think, 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. It is cool.
What I thought was weird was you can change the dunder name of a function.
That was news to me.
Oh, yeah.
Yeah, I've never tried to do that.
Neither have I.
It seems a little evil.
A little bit.
And then another article called the Tau of Python, which I think is just a cute name,
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 or objects,
but even classes themselves are objects.
Right, right.
Their classes are meta classes, right?
Which is, it's very crazy. It definitely is a mental shift, especially the meta programming. And that's something I could, I could learn more about personally as well.
Yeah, me too. And I haven't really made use of it a lot, but in, it's a kind of one of those things of if you, if you can think about the whole thing and how it fits together in just a 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. And 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 US.
So for example, they say, Indeed says the average Python developer in the US acrossS. 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 and 116,000 a year, which is
amazing, really. Yeah. Yeah, that's a good place to be, right? Yeah, and I remember when C++ was
up near one of the tops, and it's now down at number seven now. So yeah, it's, that's, it's a Python world.
All right.
So one of the things that he didn't list, which I'm confused by was, uh, that he could,
you can listen to this podcast.
It's totally bizarre.
He 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.
So we're going to, 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 have 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?
And having all that information there
is like, hey, look,
choosing Python is a really good bet.
You'll have lots of people who know it.
There's a lot of,
it's a good bet.
And I think this will help people make that case.
And I'm also a firm believer
in just resume building.
You don't know what the next job
is going to be like
and it probably will use Python somewhere. So, absolutely. All right. I bet people do some testing with Python.
Yeah, they do. And I was thrilled to have somebody write a PyTest article because it's
one of my favorites. 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 jumping into it a
little bit, he shows how easy it is of course to write tests but then
also um takes a look at one of the common things that happens is you've you grow a whole bunch of
tests and then you want to refactor them and there's a little bit about um refactoring your
tests by uh using fixtures and pulling out some of the common starting state and and then he um
jumps into a couple of the nice, one of the nice features of
PyTest, of course, is the parameterization 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 because I feel like a lot of people will write tests
and they're like, these tests are hard to maintain.
And then you look at their test code
and you're like,
why did you duplicate this bit of code 20 times?
Would you ever do this in a real app?
That's insane.
Why is this not a function
or some other thing that you can use
throughout your test, right?
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.
I've tested something locally where there was data in the database and I put it in a production.
I was about to start putting data, but it was empty at the time and the code couldn't deal with empty sets and all sorts of stuff going on where something crashed on the site and I didn't realize it.
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 AIO HTTP, 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.
So it's called Jepronto, I'm not sure how you pronounce it, but I'll link to it.
It describes itself as a screaming fast Python 3.5 and above web microframework integrating with pipelining HTTP servers based on UV loop and Pico HTTP parser.
So it came out just a few months ago. It has like 2.6,000, 2,600 stars on GitHub. And the title of
the article introducing it was handling a million requests per second with Python. 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 Gepronto, going with that one. Gepronto 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 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.
It's quite cool.
Yeah, the pipelining actually description was very, I thought that was pretty interesting.
Yeah, I hadn't really thought too much about that. So super, super cool. Yeah, the pipelining actually description was very, I thought that was pretty interesting. Yeah, I hadn't really thought too much about that.
So super, super cool.
Yeah.
And related to this, I think that somebody on Twitter was commenting that, why are we worried about speed?
Why isn't it better to be correct?
I guess I like to have both.
And 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 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? So I think it's
really interesting. I mean, to be honest, Pyramid plus MicroWSGI plus Nginx just straight up is way
fast enough for what I'm doing, even with, you know, 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 them on my show. I can't remember the number. I think it's in the 60s on TalkPython
TV. We talked about RethinkDB
and the company behind it.
I think I've heard about it
because of TalkPython, 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 it to the source code and contributed
it 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 a special especially under the Linux Foundation, and
Stripe has put together $25,000 in matching funds to match other donations. So I wish them all well
and hope to RethinkDB lives for a long time. Yeah, they definitely occupy a cool space in
the database world. So happy to see them rolling. All right, let's round out this conversation with my sixth item here, which is
the Python top 10 articles of the past year. And this comes from this interesting like work
reading app or like technical reading app called my bridge at my my bridge.co. And so this is kind
of like Zite or Flipboardboard but it's specifically focused on
technology and like reading for work and for your career okay so it's an interesting like ipad app
and whatnot 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? So the
first one is from Kenneth Hitchhiker's Guide to Python Best Practices Guidebook for Writing for
Humans. That's really cool. And then SciPy Lecture Notes, 30 essential Python tips and tricks,
computational and inferential thinking and data science,
welcome to Python cheat sheet, 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?
What should I learn with Python?
Well, this is like 60% data science,
25% web, and 25% language by my super quick estimation.
So I think that's a kind of an interesting map to draw.
Actually, I hadn't run across a lot of these articles. So I was pretty glad to hear, see some of these. 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 us message going, I can't use Python 3. Well, a friend of the show, Chip Warden,
actually added a comment.
If you want to add comments in the show,
there's a whole discuss section at the bottom of each show page
and said, hey, what do you mean people can't do this?
They should just check out Red Hat Software Collections.
So I checked it out.
Yeah, absolutely, people should check this out.
It's the latest stable updates of development technologies
for Red Hat Enterprise Linux.
Wow. It's the latest stable updates of development technologies for Red Hat Enterprise Linux. Wow.
It's cool.
So if you want to work with Node, Perl, PHP, Python, or Ruby, it is basically an approved
Red Hat Enterprise Linux way of getting Python 3, for example, on your environment.
Perfect.
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.
All right, well, thank you everyone for listening.
Brian.
Thank you.
Great to catch up with you, like always, man.
Thank you for listening to Python Bytes.
Follow the show on Twitter via at Python Bytes.
That's Python Bytes as in B-Y-T-E-S. And get the full show notes at pythonbytes.fm. If you have a news item you want
featured, just visit pythonbytes.fm and send it our way. We're always on the lookout for sharing
something cool. On behalf of myself and Brian Ocken, this is Michael Kennedy. Thank you for
listening and sharing this podcast with your friends and colleagues.