M

MagicStack Blog

magic.io · Company blog · on HN since 2016

MagicStack, the company behind uvloop and asyncpg, writes benchmark-driven posts on fast Python networking and Postgres access.

What HN saysHN commenters cite it as evidence that uvloop and asyncpg make Python asyncio fast, and note aiohttp's HTTP parser is slow by comparison.
34HN people shared it
30linked it in comments
6stories submitted
780story points
2 years agolast shared
2016people per year2026

Most-shared posts

  1. 1
    Uvloop: Fast Python networking
    26 people · 466 points · first shared 2016 · 130 comments on HN
  2. 2
    Show HN: 1M rows/s from Postgres to Python
    6 people · 299 points · first shared 2016 · 89 comments on HN
  3. 3
    Http bench
    2 people · first shared 2016
  4. 4
    Report
    2 people · first shared 2016
  5. 5
    Tcp bench
    2 people · first shared 2016
  6. 6
    Uvloop: Make Python Networking Great Again
    1 people · 15 points · first shared 2016 · 8 comments on HN

What HN people wrote when they linked it

sametmax · 2018-11-05
Python: we use the node event loop too now (https://magic.io/blog/uvloop-blazing-fast-python-networking/). But actually, you could have setup a pure Python server instead of nginx for the last 10 years with twisted. Not that you should not consider uring nginx anyway: it deals with caching, load balancing, has great tutorials, it's battle tested, and has tons of pluging. But performance wise, WSGI is not Python.
cshenton · 2017-07-04
Be careful with aiohttp, async io is great, but the actual http parser in aiohttp is super slow. See https://magic.io/blog/uvloop-blazing-fast-python-networking/ for a full write up. I've been building stuff in sanic, which is built on uvloop and is super fast. I can recommend it if you're willing to sacrifice a bit of project maturity for a solid async webserver.
jjawssd · 2017-02-01
It's worth considering Python asyncio as well for this type of work https://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/
gtirloni · 2016-12-22
"According to the Sanic author’s benchmark, uvloop could power this beast to handle more than 33k requests/s which is just insane (and faster than node.js)." I keep looking for excuses to focus on Python instead of Go and claims like this one make me happy. However, when I check the benchmarks I get confused: http://www.techempower.com/benchmarks/#section=data-r13&hw=ph&… Of course this looks amazing: https://magic.io/blog/uvloop-blazing-fast-python-networking/ But, even if in the request/second area Python might be doing great now, won't there be problem down the line with the GIL? That is, isn't async/await an island of good performance?
rdtsc · 2016-08-04
Great work, thanks for sharing. Very impressive speed. I didn't know about uvloop, that's a cool project: http://magic.io/blog/uvloop-blazing-fast-python-networking/
abuckenheimer · 2018-02-07
When people say cpython is slow they are generally pointing to two things 1) The interpreter is _slow_ 2) You can't achieve real thread based parallelism I think in general people have a high level concept of (1) as static vs. dynamic and interpreted vs compiled is an understandable trade off. CPython as an implementation generally gets type casted as slow for its default dynamism which have understandable negative performance implications[1]. However CPython also gives you lots of ergonomic ways to push your program towards the static/compiled end of the spectrum with things like pandas/numpy/numba/extensions. In general using these correctly put you within the ballpark of _faster_ languages, could you write faster assembly by hand? Sure! Is optimizing in another language worth your time? I don't know. I've never really understood (2) the lack of threading as a problem, multi process parallelism can be accomplished fairly easily if you are CPU bound or projects like uvloop[2] make async tasks fast enough to compete with any web framework out there. Furthermore even though your cpu cycle cost may be levered to a considerable point while operating over hundreds/thousands of servers doing distributed computing right is still hard and developing something like celery/airflow/luigi/dask from scratch is not cheap either. Leaning on CPython's massive ecosystem can massively lower the barrier to entry in a lot of big problems. I think there are plenty of examples of re-writes…
agentultra · 2016-07-22
You can write a fast server in Python 3 that can benchmark well against Node [0]. The author tried to sell us on the idea that Python is slow because Django is slow and you shouldn't use Ruby because Rails is slow. You should just use Node because its fast. Well I don't know about you but I've seen slow Node applications too. It all comes down to data. If you really want to maintain your performance goals you have to include them in your design. You have to design for your data. Show me your data and I can write the program. Design it well and you can scale up when the time comes with minimal effort. Besides there are other factors to consider such as familiarity with the tools, correctness of the implementation, etc. Javascript is great and all but it is incredibly easy to make errors that will go unnoticed until it hits production. The law of large numbers won't protect you if you're used to the blanket of obscurity. And so I find you need many more layers of tooling and choose your subset of the language carefully to maximize its use... something that you don't have to do as much with OCaml or Haskell for instance. Hence, "just use Node because its fast," is misguided at best. (And I'm not even a Node hater.. I maintain a number of Node applications presently). [0] http://magic.io/blog/uvloop-blazing-fast-python-networking/
kirbyfan64sos · 2022-05-18
AFAIK, it depends on your bottlenecks. In terms of actual compute speed, Python is still significantly slower, and although 3.11's changes will help quite a bit, V8 is also just insane. In terms of I/O speed, uvloop (https://magic.io/blog/uvloop-blazing-fast-python-networking/) can beat Node quite handily, so if you're more concerned with being able to handle requests than doing anything major during those requests, Python might be comparable.
1st1 · 2020-03-12
Here's a benchmark [1] against aiopg, which is psycopg2+asyncio. [1] http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/report.ht…
achillean · 2019-09-14
It hasn't been a problem for most of our things at Shodan. I think there's a lot of confusion about when to use multithreading vs non-blocking sockets. Most security tools tend to use multithreading when they should just use non-blocking sockets. With Python3 you can also swap out the scheduler if you want better performance: https://magic.io/blog/uvloop-blazing-fast-python-networking/
wenc · 2018-03-13
There is also a drop-in replacement for asyncio called uvloop [0]. It claims to be faster than asyncio, gevent, node.js, etc. and comparable to golang. [0] https://magic.io/blog/uvloop-blazing-fast-python-networking/
Jach · 2017-10-18
If you start getting into decently designed systems territory, you're still going to have trouble beating some of the stuff that comes out of the Python/Lisp/Node communities. For instance: https://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/ Anyway, if you're locally looping for hundreds/thousands of queries to the database, instead of writing one query or calling a stored procedure, you're probably doing things wrong.
Rotareti · 2017-10-18
> Why does anyone write web apps in Python? The new generation of Python web frameworks is pretty fast (check out Sanic[0][1] for example), Python has a huge growing ecosystem, you get rapid time to marked and if you find some part of your application to be the bottleneck, you can replace it with C/Rust, which you probably don't need, because your company won't ever scale as far. [0] https://github.com/channelcat/sanic [1] https://magic.io/blog/uvloop-blazing-fast-python-networking/
kbutler · 2017-06-15
Python I/O also releases the GIL (and has for decades). And FWIW, libuv is also available in Python. https://magic.io/blog/uvloop-blazing-fast-python-networking/ claims significantly faster than nodejs.
rmrfrmrf · 2017-06-15
> Python I/O also releases the GIL (and has for decades). I didn't know this; thanks! I'm not familiar with Python internals at all (in fact, I had to look up what GIL was when I read the article). Seems strange, then, that the author would imply a contrast between Python and node.js (which I'm now realizing was your point to begin with). Thanks for being patient with me :). > And FWIW, libuv is also available in Python. > https://magic.io/blog/uvloop-blazing-fast-python-networking/ claims significantly faster than nodejs. Yep! There are bindings for quite a few languages now. The only reasons why I conflate libuv with node.js are because libuv was developed specifically for node (as a cross-platform libev implementation) and because libuv comes with node by default.
elnygren · 2017-05-07
Python3 is a totally different beast nowadays from Python2. The reason is async/await. It can handle Node.js style event loop / asynchronous code very well -- with uvloop, python 3.5+ is actually faster than Node.js (close to Go). https://magic.io/blog/uvloop-blazing-fast-python-networking/ IMHO: after 3.5, we are clearly in the next iteration of the language.
RubyPinch · 2017-04-28
https://magic.io/blog/uvloop-blazing-fast-python-networking/http-bench… from the makers of uvloop (for a toy example) it seems the main bottleneck when using aiohttp is aiohttp itself, which practically makes the use of uvloop irrelevant
mixmastamyk · 2017-04-27
There's a link on the page which digs in a bit more: https://magic.io/blog/uvloop-blazing-fast-python-networking/
agounaris · 2017-04-09
Got you something faster than go, in python... switch back to python :P https://magic.io/blog/uvloop-blazing-fast-python-networking/
brettcannon · 2016-11-07
Is that still true? Some uvloop benchmarking has shown it to be equivalent to gevent when using streams: https://magic.io/blog/uvloop-blazing-fast-python-networking/ . Plus Python 3.6 has a bunch of optimizations for asyncio where all of these numbers are going to have to be re-evaluated.
mangecoeur · 2016-10-12
If its server-side performance you are interested in you might also be interested in uvloop, which brings node's event loop library to async python with impressive results https://magic.io/blog/uvloop-blazing-fast-python-networking/ Personally while I appreciate what PyPy are trying to do, for a lot of real world use cases you can get really impressive performance out of python using the right libraries (see: the entire Python scientific computing stack).
allan_s · 2016-08-07
So I guess it will integrate well with uvloop http://magic.io/blog/uvloop-blazing-fast-python-networking/ ? (which is lacking an http parser :) ) May I dream that this + uvloop + asyncpg [0] and we can start to have something to build simple web services à la tornado that leverage python3.5? [0] http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/
RedCrowbar · 2016-08-05
12 in the particular case of 1M rows/s. The details are available in the benchmark report: http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/report.ht…
greut · 2016-06-21
To make Python fast in that regard, you'll have to rely on C-based libraries (C as in Cython) like httptools or libuv. http://magic.io/blog/uvloop-blazing-fast-python-networking/
SEJeff · 2016-06-21
FWIW: There is a new set of async / await bits in CPython 3.5 that are allowing some really interesting new performance profiles. http://magic.io/blog/uvloop-blazing-fast-python-networking/ This is almost exactly on par with golang's net/http for a simple echo server, yet it is written in python.
kevinastone · 2016-05-04
The benchmark (simple echo server) results were right there in the blog post: http://magic.io/blog/uvloop-blazing-fast-python-networking/tcp-bench.h…
xapata · 2018-05-03
I'm getting confused. Are you trying to do parallel compute or parallel networking? If parallel networking, the benchmarks I've seen set Python asynchronous IO at about the same speed as Golang. The folks at Magicstack reported that Python's bottleneck was parsing HTTP (https://magic.io/blog/uvloop-blazing-fast-python-networking/). Note their uvloop benchmark was about as fast or faster than the equivalent Golang code. If parallel compute, then multiprocessing is the way to go and Python's futures module ain't clumsy. It's just ``pool.submit(func)`` or ``pool.map(func, sequence)``. If you're asking for parallel compute via multithreading, you're going against the wisdom of shared-nothing architecture. Besides, pretty soon you'll want to go distributed and won't be able to use threads anyway. In contrast to your experience, I find Python makes it easy to write efficient code. Getting rid of the irrelevant details lets me focus on clear and efficient algorithms. When I need heavy compute, I sprinkle in a little NumPy or Numba. My bottleneck is (de)serialization, but Dask using Apache Arrow should solve that problem.
giancarlostoro · 2016-11-08
Let me point out two alternatives: Cython which is very Pythonic looking, and compiles to C and produces amazing projects including UVLoop which is a drop-in module for asyncio for Python 3 that will speed up asyncio: https://magic.io/blog/uvloop-blazing-fast-python-networking/ https://github.com/MagicStack/uvloop Note how GitHub claims it's all mostly Python code ;) That's because Cython like I said looks Pythonic. There's other examples, but I think this is one of the one's that come to mind the most to me. There's also D which is called Native Python by some (unlike projects like Go and Rust, you can have your Object Oriented Programming (optional like in C++), and concurrency / parallelism too and other goodies like built-in unit testing, when you compile your code your unit tests are ran but not included in the final binary): http://bitbashing.io/2015/01/26/d-is-like-native-python.html https://blog.experimentalworks.net/2015/01/the-d-language-a-sweet-spot… If it's been more than a few years since you've evaluated D you might want to check it out again, it may be worth your time. D is a language I knew about for years, and recently is where I've come to appreciate it for it's many features. D has things like array slicing, [OPTIONAL] Garbage Collection, an amazing Web Framework called Vibe.d with it's own template engine called Diet-: http://vibed.org/ https://vibed.org/blog/posts/introducing-diet-ng Things I like is Vibe.d is not just a…
wrl · 2016-07-17
> It's objectively not perfect, but then most languages have problems. Let me be clear here: JS is not really any better or any worse than any other interpreted languages. Yeah, I can name a few language-level problems (whoever decided that Promises should silently eat exceptions was wrong), but the big problems are not unique. Things like awful numeric performance (I've done crypto in JS), horrible multithreading support (Python and Ruby have GILs so it's roughly the same thing), etc etc. The difference is that JS/web programmers seem to be the only ones saying that things written in their language and platform of choice (JS/HTML/CSS webapps, inside or outside of Electron) are the future everybody wants. Like the ego-stroking whenever somebody posts a new Node or Electron tool that had no reason to be written in JS except that the developer just didn't want to use another language isn't weird. Like 123mb for a terminal emulator isn't ridiculous. Javascript brings nothing to the table except that it's the only language you can use for web programming. Nothing. The execution model is awful as well, since apparently in order to get any sort of decent performance in a webapp these days you need to maintain a shadow copy of the DOM just so you can hack around the browser's layout engine. > JavaScript has some of the most advanced features of languages available today, including lambdas, closures, and asynchronous coding patterns that make it faster at dealing with IO than…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close