4 ms·
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 con
by ikken 11y 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.
- findjashua 11y agofyi: ES2016 javascript also supports async/await, and you can use them today w babel
- Kudos 11y agoNo 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.
- findjashua 11y agoi 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?
- Kudos 11y agoIt's going to make it in some form, possibly even it's current form, but it isn't formally part of the spec yet.
- tomchristie 11y agoAnything 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.
- ikken 11y agoUnfortunately 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 https://gist.github.com/gdamjan/d7333a4d9069af96fa4d
- oliwarner 11y agoI'm actually tearing up here. That is... Beautiful.
- 1st1 11y agoThanks 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?
- ikken 11y agoYes, 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 http://aiohttp.readthedocs.org/en/stable/gunicorn.html