M
Mike Bayer
techspot.zzzeek.org · Personal blog · on HN since 2010
Mike Bayer, author of SQLAlchemy, writes about Python, databases, ORMs, and software patterns.
What HN saysCommenters repeatedly cite his 2015 post on asynchronous Python and databases as a key reference showing async often isn't faster for database-backed web apps.
40HN people shared it
27linked it in comments
19stories submitted
290story points
3 years agolast shared
2010people per year2026
Most-shared posts
- 1Asynchronous Python and Databases22 people · 218 points · first shared 2015 · 72 comments on HN
- 2Patterns Implemented by SQLAlchemy3 people · 8 points · first shared 2012 · discussion on HN
- 3SQLAlchemy performance analyzed with RunSnakeRun (SQLA v0.5, v0.6 and v0.7)2 people · 34 points · first shared 2010 · 3 comments on HN
- 4The Absolutely Simplest Consistent Hashing Example2 people · 4 points · first shared 2012 · discussion on HN
- 5Gerrit Is Awesome2 people · 2 points · first shared 2019 · discussion on HN
- 6Magic, a "new" ORM2 people · 1 points · first shared 2011 · discussion on HN
- 7Homepage2 people · first shared 2017
- 8Supporting a (Very Interesting) New Database1 people · 7 points · first shared 2012 · discussion on HN
- 9Server Side Templates and API Centric Development1 people · 7 points · first shared 2012 · discussion on HN
- 10Guide to Python 3 Porting1 people · 3 points · first shared 2011 · discussion on HN
- 11Using Beaker for Caching? Why You'll Want to Switch to dogpile.cache1 people · 2 points · first shared 2012 · discussion on HN
- 12Pycon 2012 : Hand Coded Applications with SQLAlchemy (slides and video)1 people · 1 points · first shared 2012 · discussion on HN
- 13SQLAlchemy Enum Recipe1 people · 1 points · first shared 2014 · discussion on HN
- 14SQLAlchemy at PyGotham - my talk about ORMs, "abstraction" and Automation1 people · 1 points · first shared 2011 · discussion on HN
- 15ORM Thoughts (in 140 x 5 characters) — by Michael Bayer, SQLAlchemy creator1 people · 1 points · first shared 2011 · discussion on HN
What HN people wrote when they linked it
kissgyorgy · 2022-11-10
Fully agree with this! Just stick to Flask/Django if you doing a simple website/API. Async also makes DB connections slower, here is a great piece from Mike Bayer from years ago: https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databas…
Lunrtick · 2022-08-17
The author of SQLAlchemy (which recently released great async support) wrote a great post about how async can actually lead to a small decrease in performance compared to the older threading model, at least for db related functions in a web backend context. [1]
For websockets or lots of network calls, you can't really beat async though.
[1] https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databas…
jgehrcke · 2021-10-16
By the way Mike I think https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databas… is still one of the best articles on the topic of "python and concurrency". So many important insights for real-world engineering.
Thanks for all your work in the Python ecosystem!
zzzeek · 2020-06-12
I am SUPER happy someone else is finally looking at this. It is long past time that the reflexive use of asycnio or systems like gevent/eventlet for no other reason than "hand-wavy SPEED" come to an end. That web applications that literally serve just one user at at time are built in Tornado for "speed". (my example for this is the otherwise excellent SnakeViz: https://jiffyclub.github.io/snakeviz/ which IMO should have just used wsgiref).
As the blog post apparently cites as well (woo!), I've written about the myth of "async == speed" some years ago here and my conclusions were identical.
https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databas…
sametmax · 2018-07-13
NodeJS event loop is fantastic.
However, it's not that relevant for most db workload. We had the same debate in Python: do we async our db libs or keep using threads ?
Experts say: http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
And this is despite the way the Python community adopted libuv with the uvloop lib.
TypeORM does look super nice, thanks. Does it handle well introspection ?
magpi3 · 2017-11-03
Click on his username to read his profile which includes a link to his website http://techspot.zzzeek.org
harlowja · 2015-04-18
IMHO the following are much more useful to read over:
* https://review.openstack.org/#/c/153298/
* http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
* http://lists.openstack.org/pipermail/openstack-dev/2014-February/threa…
And others...
j-kidd · 2012-03-07
> The main thing one needs to think about when coding an app in a load balanced environment is that there’s no guarantee that request ‘n+1′ is going to land on the same server as request ‘n’, so you need to handle sessions in a centralized/db manner so that the cookies in the browser link you up to the proper session regardless of what server you hit.
Instead of doing it in a centralized/db manner, Beaker allows sessions to be distributed client side:
http://techspot.zzzeek.org/2011/10/01/thoughts-on-beaker/
It was one of the best things I learned last year.
SatvikBeri · 2017-12-18
(Mike Bayer is zzzeek: http://techspot.zzzeek.org/)
codethief · 2022-08-03
> In order for async to be popular it needs to be the default way of writing python. Right now its an after thought for writing “high performance” python.
Might this have to do with the fact that the (lack of) performance of asyncio is exactly the issue here?
I remember reading a blog post by zzzeek (the SQLAlchemy author who's also participating in our discussion here) about precisely this issue a while ago. Not sure but it might have been this one:
https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databas…
brandmeyer · 2022-01-23
This is a widely-held belief, but it isn't true. Maybe once upon a time in the land of spinning rust that was true, but it certainly isn't now. Databases are fast enough that a scripting language frequently is the performance bottleneck.
https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databas…
throwdbaaway · 2021-02-19
Good article, but I can't help but notice a gaping hole in the benchmark -- why was there no attempt to run gunicorn in multi-threaded mode?
The article has a link to https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databas… but failed to mention the key takeaway from the article:
> threaded code got the job done much faster than asyncio in every case
captain_price7 · 2021-02-12
rsyring · 2018-10-01
Grandparents concern about async is documented here:
http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
theptip · 2018-04-23
An interesting deep dive on why this is the case (from 2015), in case anyone wants to know more:
http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
miracle2k · 2018-04-02
I found this article extremely persuasive, and it matches my own experiences with asyncio: The performance gain might be there if most of what you do is waiting for a network response, but even a small amount of data processing will make your program CPU bound pretty quickly.
http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
quentinp · 2018-03-13
I think many people agree that speed is not a reason to choose non-blocking IO over threads.
However, many people do believe that async/await and event loops make reasoning about non-blocking IO much easier. Has your opinion changed since http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
anentropic · 2017-08-30
yes, not just the memory... for models with lots of fields, in Python+Django, the time overhead of instantiating these complex heavyweight objects can really add up if you have a whole 'page' of them
I always figured the main overhead was doing I/O with the db, but in these cases it's not always so
interesting blog post about this from the creator of SQLAlchemy:
http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
Walkman · 2017-07-15
Mike Bayer wrote a really interesting article about this topic 5 years ago: http://techspot.zzzeek.org/category/mako/
These techniques are easier with the Pyramid framework.
Dowwie · 2016-08-04
Does this library address any of the issues/concerns that Mike Bayer discussed in this earlier blog post?
http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
sandGorgon · 2015-10-17
hey - thanks for replying.
if Pypy + asyncio was available, would you have built everything using that stack ? There have been all these benchmarks that asyncio is so much slower than threads [1]
How would you compare that with Go ?
[1] http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
makmanalp · 2014-05-26
I'm just waiting for zzzeek to publish a blog post on how to implement this on top of sqlalchemy core, like this post [1]. :) Seriously though, sqlalchemy ORM layer already does this. Why not leverage all the existing features and support it has? Also, it's an easier sell for a $100 piece of software: "If you're using sqlalchemy, you can migrate to pony immediately."
[1] http://techspot.zzzeek.org/2011/05/17/magic-a-new-orm/
mace · 2011-09-26
Slides from talk: http://techspot.zzzeek.org/files/2011/sqla_arch_retro.key.pdf
kapilkaisare · 2010-12-06
Mike Bayers response: http://techspot.zzzeek.org/2010/12/04/in-response-to-stupid-template-l…
Steve Holden's response: http://holdenweb.blogspot.com/2010/12/templating-systems.html
Armin Ronacher's response: http://lucumr.pocoo.org/2010/12/5/not-so-stupid-template-languages/
corford · 2017-09-01
> I want to scream every time somebody suggests threading as a solution to non-blocking database calls and HTTP requests.
Rather than screaming, perhaps read this (from the developer of the Python world's most popular ORM) to see why they might be suggesting it:
http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-database…
tl;dr:
If your database is properly setup and provisioned it shouldn't be a source of blocking I/O (and if it is, throwing thousands of concurrent async connections at it isn't going to help you). For standard CRUD applications, your program will spend much more time in CPU processing the database response than it will waiting on the database to deliver it.
Furthermore, when querying a traditional RDBMS like postgres or mysql, safe concurrency is ultimately enforced by the ACID capabilities built in to the database itself i.e. transactions. Whether you're using async, threads, multiple processes or something else entirely doesn't matter. Given the database itself controls how much concurrency it can support, real world tests (at least for Python) show that threads give you better performance than event driven callbacks.
Of course, threads are completely wrong for the HTTP side of things and this is where async (e.g. nginx or node) offers all of its advantages. That doesn't mean it's wrong to put your DBMS behind a thread pool.