In the standard Python 3.4 library, the
asyncio module appeared at the time, which made it possible to quickly and conveniently write asynchronous code. And as of Python 3.5, async / await constructions
were added to the syntax, which finally formed the asynchrony “out of the box” as a beautiful and harmonious part of the language.
Although asyncio itself allows writing high-load web applications, performance optimization was not a priority when creating a module.
')
One of the authors of the mentioned PEP-492 (async / await) Yuri Selivanov (on Habré is
1st 1 ,
his twitter ) took up the development of an alternative implementation of the event loop for asyncio -
uvloop . Yesterday the first alpha version of the module came out, as the author wrote a
detailed post .
In short, uvloop works about 2 times faster than Node.js and is almost as good as Go.
Using
uvloop is written in Cython and is based on
libuv .
You can install the module as standard (Windows is not currently supported):
pip install uvloop
Using is also not difficult:
import asyncio import uvloop asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
Now any call to asyncio.get_event_loop () will return an instance of uvloop.
Performance
More information about benchmarks (methodology and conclusions) can be read
in the original , below only the final graphs.
Results for simple TCP requests of different sizes:

HTTP requests:
