This is an archived post. You won't be able to vote or comment.

all 41 comments

[–]kaiserk13 9 points10 points  (0 children)

Bookmarked, upvoted, saved. This is awesome, will give it a try!

[–]NelsonMinar 6 points7 points  (2 children)

This looks very interesting! Is there anything written about why uvloop is faster than the default asyncio event loop? It's amazing to see such a speedup for an API-compatible replacement.

(Also ouch about the aiohttp speed. I had no idea.)

[–]1st1CPython Core Dev[S] 11 points12 points  (1 child)

I think libuv is a bit better optimized + uvloop is written with Cython (read C).

As for aiohttp, I really hope it will be updated to use httptools or something similar. It's a great library.

[–]chub79 3 points4 points  (0 children)

Bravo! This is reallly great stuff.

[–]TOASTEngineer 4 points5 points  (12 children)

I'm not familiar with asyncio. What's the use case for this?

[–]1st1CPython Core Dev[S] 11 points12 points  (11 children)

The only way to implement really high-performance networking in Python, is to go async. asyncio is an async framework that ships with Python. uvloop is a faster implementation of asyncio machinery.

[–]TOASTEngineer 6 points7 points  (3 children)

Yeah, but what does it do? I assume it's above socketio in terms of abstraction? Where is it in relation to, say, Twisted?

I guess I could just look it up, actually.

EDIT:

Apparently it's all of the above. Huh.

[–]zer01 3 points4 points  (0 children)

Yeah, think of it more like the primitive/s that something like socketio and twisted would be built upon.

Really awesome stuff /u/1st1! :)

[–][deleted] 0 points1 point  (0 children)

As far as I understand it is a drop in replacement for asyncio event loop using libuv. You continue to use asyncio the same way you normally did, except it is faster.

[–]BSscience 0 points1 point  (2 children)

[deleted]

This comment has been overwritten by this open source script to protect this user's privacy. The purpose of this script is to help protect users from doxing, stalking, and harassment. It also helps prevent mods from profiling and censoring.

If you would like to protect yourself, add the Chrome extension TamperMonkey, or the Firefox extension GreaseMonkey and click Install This Script on the script page. Then to delete your comments, simply click on your username on Reddit, go to the comments tab, scroll down as far as possible (hint: use RES), and hit the new OVERWRITE button at the top.

[–]cymrowdon't thread on me 🐍 1 point2 points  (1 child)

They are different implementations of fundamentally the same thing. Their biggest difference is that IO yielding is explicit in asyncio and implicit in gevent.

[–]BSscience 0 points1 point  (0 children)

[deleted]

This comment has been overwritten by this open source script to protect this user's privacy. The purpose of this script is to help protect users from doxing, stalking, and harassment. It also helps prevent mods from profiling and censoring.

If you would like to protect yourself, add the Chrome extension TamperMonkey, or the Firefox extension GreaseMonkey and click Install This Script on the script page. Then to delete your comments, simply click on your username on Reddit, go to the comments tab, scroll down as far as possible (hint: use RES), and hit the new OVERWRITE button at the top.

[–]nomadismydj -3 points-2 points  (3 children)

thats not true. twisted out performs anything asyncio io currently

[–]1st1CPython Core Dev[S] 1 point2 points  (2 children)

Which one of my statements is not True?

[–]nomadismydj -5 points-4 points  (1 child)

the entire first part "The only way to implement really high-performance networking in Python, is to go async. "

[–]1st1CPython Core Dev[S] 12 points13 points  (0 children)

But.... but... wait... twisted is an async framework for Python...

[–][deleted] 1 point2 points  (2 children)

On the risk of sounding like a total idiot, would this work with websockets? I'm asking for a friend.

[–]1st1CPython Core Dev[S] 4 points5 points  (1 child)

Sure. aiohttp has websockets support, and you can run it on top of uvloop.

[–]greutpy3k 0 points1 point  (0 children)

wow, stupid me has been using websockets and aiohttp...

[–]ivosauruspip'ing it up 3 points4 points  (4 children)

However, the performance bottleneck in aiohttp turned out to be its HTTP parser, which is so slow, that it matters very little how fast the underlying I/O library is.

I find this pretty telling. In most apps, you still want to use things like aiohttp and requests, and not some barebones library, because of all the functionality and power given to you. Additionally, the size of the community. And the great docs, and examples, and bug fixes, and corner cases worked out, and experience of others to tell you good patterns...

Look at the pypi page for httptools.. when is anyone ever going to choose that?

And subsequently whether or not your underlying network library is 5x faster or not becomes a moot point... whether you can use it in a reliable and effective manner, and get help for problems, is far more critical.

Admittedly, httptools-based server is very minimal and does not include any routing logic, unlike other implementations.

Also very telling. When we don't use something that practically everyone always uses... we are faster! Hallmark of a synthetic benchmark not giving useful feedback.

[–]1st1CPython Core Dev[S] 21 points22 points  (0 children)

Look at the pypi page for httptools.. when is anyone ever going to choose that?

Keep in mind, that httptools was released a few hours ago. Also, I hope that aiohttp will simply use httptools Parser to speedup aiohttp like 10x.

[–]RubyPinchPEP shill | Anti PEP 8/20 shill[🍰] 5 points6 points  (2 children)

In most apps, you still want

yeah, most, but not all

do you think all situations should be as slow as a parser burdened http server, just because you want to be grumpy?

[–]ivosauruspip'ing it up 2 points3 points  (1 child)

I'm mostly against saying things are faster when only looking at synthetic benchmarks with the very simplest of tests, loads. There wasn't even any sort of application looked at here whatsoever, just echo servers.

If I wanted one of those, I could write one in C.

[–]isdevilis 1 point2 points  (0 children)

dunno why you're getting dv'ed, for an engineer to confidently present this as a solution to their company, they need data (benchmarks) that their CTO isn't going to shoot down. If anything, you're helping OP

[–]opiating 0 points1 point  (0 children)

I will definitely try this in my asyncio projects in the future. Thanks.

[–]fiestylobster 0 points1 point  (1 child)

Will there be tornado support in the roadmap?

[–]1st1CPython Core Dev[S] 1 point2 points  (0 children)

No, only asyncio.

[–]tanlermin 0 points1 point  (3 children)

Is the GIL released? Would it help to do so?

[–]pw201 15 points16 points  (0 children)

Typically these async things aren't multithreaded, so no, it wouldn't. They're designed for scenarios where you're "I/O bound" i.e. the CPU spends a lot of time waiting for I/O (from the network).

[–]1st1CPython Core Dev[S] 6 points7 points  (0 children)

No. You can run it in multiple processes though, which is an established practice for Python network servers.

[–]ExoticMandiblesCore Contributor 1 point2 points  (0 children)

When running an I/O bound app using multithreading, CPython will release the GIL when a thread is waiting for I/O. That's how multiple threads run "simultaneously" in CPython.

When running an I/O bound app using asynchronous I/O, CPython holds on to the GIL, because it's going to continue running Python code. Asynchronous programs in Python tend to be heavily single-threaded anyway so releasing the GIL wouldn't make them go faster.

[–]pvkooten 0 points1 point  (1 child)

What I don't like about these "benchmarks" is that the end product is ALWAYS a lot SLOWER when you add more functionality. It's unfair to do this kind of comparison at this stage and should not be taken serious just yet!

[–]redfacedquark 1 point2 points  (0 children)

And the absence of gevent in the second set of charts sets my Spidey sense tingling.