uvloop

109 views
Skip to first unread message

Yury Selivanov

unread,
May 3, 2016, 6:43:32 PM5/3/16
to python-tulip
Hi,

Please check out a new asyncio event loop implementation uvloop. Here's
a blog post about it:
http://magic.io/blog/uvloop-make-python-networking-great-again/

Thanks,
Yury

Gustavo Carneiro

unread,
May 3, 2016, 7:50:47 PM5/3/16
to Yury Selivanov, python-tulip
Really good work!

Question: could the asyncio-streams results be affected by the performance bottleneck found (and fixed) by Коренберг Марк?  https://github.com/python/asyncio/pull/339

It would be interesting if you could compare with that patch applied, to see if it brings it closer to the better performance.  It would be a shame (and surprising) if using streams were so much slower than using lower level primitives...

Thanks.

--
Gustavo J. A. M. Carneiro
Gambit Research
"The universe is always one step beyond logic." -- Frank Herbert

Justin Mayfield

unread,
May 4, 2016, 12:35:18 AM5/4/16
to python-tulip
Wow.  Testing with my asyncio libs now..

Stefan Scherfke

unread,
May 4, 2016, 3:46:27 AM5/4/16
to Yury Selivanov, python-tulip
Hi Yury,
very nice work. aiomas (https://aiomas.readthedocs.io/) works very well
with it.

I only found one problem: the default event loop's create_task() accepts
the empty string '' as host name and will bind the server to all
available interfaces. With uvloop however, I get a TypeError:

File "uvloop/loop.pyx", line 1026, in create_server (uvloop/loop.c:19287)
File "uvloop/loop.pyx", line 509, in uvloop.loop.Loop._getaddrinfo (uvloop/loop.c:12059)
TypeError: host must be a str or bytes


The low-level aiomas example attached at the end of this mail takes ~22s
with the default event loop but only ~15s with uvloop, which is ~45%
faster. :-)

Cheers,
Stefan

#
# uvloop benchmark
#
import asyncio

import aiomas
import uvloop


asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())


N_CLIENTS = 100
N_MSGS = 1000


async def handle_client(channel):
"""Handle a client connection."""
try:
while True:
req = await channel.recv()
# print(req.content)
await req.reply('cya')
except ConnectionResetError:
await channel.close()


async def client():
"""Client coroutine: Send a greeting to the server and wait for a
reply."""
channel = await aiomas.channel.open_connection(('localhost', 5555))
for _ in range(N_MSGS):
rep = await channel.send('ohai')
# print(rep)
await channel.close()


server = aiomas.run(aiomas.channel.start_server(('localhost', 5555),
handle_client))
t_clients = [client() for _ in range(N_CLIENTS)]
aiomas.run(asyncio.gather(*t_clients))


server.close()
aiomas.run(server.wait_closed())

Yury Selivanov

unread,
May 4, 2016, 12:44:29 PM5/4/16
to python...@googlegroups.com


On 2016-05-04 3:46 AM, Stefan Scherfke wrote:
> Hi Yury,
>
>> Am 2016-05-04 um 00:43 schrieb Yury Selivanov <yseliv...@gmail.com>:
>>
>> Hi,
>>
>> Please check out a new asyncio event loop implementation uvloop.
>> Here's a blog post about it:
>> http://magic.io/blog/uvloop-make-python-networking-great-again/
>>
>> Thanks, Yury
> very nice work. aiomas (https://aiomas.readthedocs.io/) works very well
> with it.
>
> I only found one problem: the default event loop's create_task() accepts
> the empty string '' as host name and will bind the server to all
> available interfaces. With uvloop however, I get a TypeError:
>
> File "uvloop/loop.pyx", line 1026, in create_server (uvloop/loop.c:19287)
> File "uvloop/loop.pyx", line 509, in uvloop.loop.Loop._getaddrinfo (uvloop/loop.c:12059)
> TypeError: host must be a str or bytes

Thanks for submitting a PR! This is now fixed in v0.4.11.

>
>
> The low-level aiomas example attached at the end of this mail takes ~22s
> with the default event loop but only ~15s with uvloop, which is ~45%
> faster. :-)

This is great to hear! Thanks for sharing this!

Yury

Yury Selivanov

unread,
May 4, 2016, 12:45:11 PM5/4/16
to python...@googlegroups.com


On 2016-05-04 12:35 AM, Justin Mayfield wrote:
> Wow. Testing with my asyncio libs now..


Great! Please share your results!

Yury

Yury Selivanov

unread,
May 4, 2016, 12:47:21 PM5/4/16
to Gustavo Carneiro, python-tulip


On 2016-05-03 7:50 PM, Gustavo Carneiro wrote:
> Really good work!
>
> Question: could the asyncio-streams results be affected by the
> performance bottleneck found (and fixed) by Коренберг Марк?
> https://github.com/python/asyncio/pull/339

Maybe, we'll see!

>
> It would be interesting if you could compare with that patch applied,
> to see if it brings it closer to the better performance. It would be
> a shame (and surprising) if using streams were so much slower than
> using lower level primitives...

I'll take a closer look later at the streams. Maybe we can optimize
them a bit. For instance, I want to re-implement asyncio.Future in C
(there is an issue for that on bugs.python.org) which boosts streams
performance 10-15%.

Yury

Ludovic Gasc

unread,
May 5, 2016, 5:24:09 PM5/5/16
to Yury Selivanov, python-tulip
Hey Yury,

Thanks a lot for this amazing job, it's awesome :-)
Theses results are beyond my expectations, it was my hope when I've tried to benchmark aiouv.

Moreover, I hope it will help to improve efficiency of HTTP stack in AsyncIO ecosystem, your benchmark values give me a good taste ;-)

However, at least to me, aiohttp.web has a very good high-level API to deliver quickly REST APIs, I don't know if it's technically possible to have the same efficiency like in your benchmarks with httptools+aiohttp-like API (or aiohttp itself ?).

Nevertheless, even if no efficient high level API appears on the top of httptools, I'll integrate that for FrameworkBenchmarks, to confirm theses numbers and have more implementation to compare.

Maybe, see you at EuroPython ?

Have a nice week.

--
Ludovic Gasc (GMLudo)

Yury Selivanov

unread,
May 5, 2016, 5:27:36 PM5/5/16
to Ludovic Gasc, Yury Selivanov, python-tulip
Hi Ludovic,

> On May 5, 2016, at 5:23 PM, Ludovic Gasc <gml...@gmail.com> wrote:
>
> Hey Yury,
>
> Thanks a lot for this amazing job, it's awesome :-)
> Theses results are beyond my expectations, it was my hope when I've tried to benchmark aiouv.

Thanks!

[..]
> However, at least to me, aiohttp.web has a very good high-level API to deliver quickly REST APIs, I don't know if it's technically possible to have the same efficiency like in your benchmarks with httptools+aiohttp-like API (or aiohttp itself ?).

I hope Andrew Svetlov will take a look into this if he has some time. Either using httptools from aiohttp, or if aiohttp will have its own binding is fine with me. I’d be glad to help.

>
> Nevertheless, even if no efficient high level API appears on the top of httptools, I'll integrate that for FrameworkBenchmarks, to confirm theses numbers and have more implementation to compare.

Maybe I’ll work on adding a fully-featured HTTP protocol to httptools. But I don’t have any timeline for that yet.

>
> Maybe, see you at EuroPython ?

I have two talks scheduled there, so yeah ;)

Yury

Nikolay Kim

unread,
May 5, 2016, 5:40:54 PM5/5/16
to Yury Selivanov, Ludovic Gasc, Yury Selivanov, python-tulip
i think replacing parser in aiohttp with httptools should be relatively simple task.

Ludovic Gasc

unread,
May 5, 2016, 5:46:31 PM5/5/16
to Yury Selivanov, Yury Selivanov, python-tulip
Maybe I’ll work on adding a fully-featured HTTP protocol to httptools.  But I don’t have any timeline for that yet.

Don't hesitate to ping me if you have the time to do that one day, even if it's less "dev-friendly" than aiohttp.web or flask.
 
> Maybe, see you at EuroPython ?

I have two talks scheduled there, so yeah ;)
 
Then, I'd like to buy you are a beer/soft drink ;-)
Reply all
Reply to author
Forward
0 new messages