Hacker News new | ask | show | jobs
by ikken 3928 days ago
I've been using the new async/await syntax to write beautiful asynchronous websockets server and I fell in love with it. It handles hundreds of thousands of concurrent connections (on top of aiohttp) and the code is so much cleaner than it would be with i.e. NodeJS and Express and Promises. It reads like a serial code.

I think benchmarking asyncio with any type of CPU bound tasks misses the point. Previously we were relying on hacks like monkeypatching with gevent, but now we've been presented with clean, explicit and beautiful way to write massivly parralel servers in Python.

3 comments

Anything you can share? Some good examples of networking code with async/await would be incredibly helpful. The documentation covers the primatives but I have a hard time putting it all together.
Unfortunately the code is not open source - I'll try to open parts of it in the future.

But please do check this simple gist I found some time ago that helped me understand how powerful asyncio is:

https://gist.github.com/gdamjan/d7333a4d9069af96fa4d

I'm actually tearing up here. That is... Beautiful.
fyi: ES2016 javascript also supports async/await, and you can use them today w babel
No it doesn't. It just hit stage 3 in TC39 yesterday, meaning browsers should be considering implementing it experimentally in order to solicit feedback from developers. When it progresses beyond that you can start calling it ES2016.
i stand corrected, somehow i was under the impression that they were a part of es7 (es2016). So does this mean, there's still a chance that they might not make it?
It's going to make it in some form, possibly even it's current form, but it isn't formally part of the spec yet.
Thanks for writing this!

> [..] It handles hundreds of thousands of concurrent connections [..]

Is it a single process application, or you use a few OS processes behind some load balancer?

Yes, it is a single process application. But to utilize all cores I use Gunicorn to spawn multiple processes.

http://aiohttp.readthedocs.org/en/stable/gunicorn.html