3 ms·
Indeed, the postgres drivers I’ve encountered are all blocking. On this topic, a warning for anyone trying to implement async rails with postgres: beware. Conn
by ninkendo 5y ago
Indeed, the postgres drivers I’ve encountered are all blocking.
On this topic, a warning for anyone trying to implement async rails with postgres: beware. Connections are per-thread in the ‘pg’ gem (and every other driver I’ve used), so one client’s connection may commit/abort another client’s transaction, and they end up stomping all over each other. Which you will only observe under load.
There’s an eventmachine-based driver for postgres but it’s almost completely unmaintained afaict, and doesn’t work with any new rails versions.
I spent a ton of effort migrating an internal rails app to eventmachine, only to realize at the very end that it fundamentally doesn’t work with typical CRUD/database apps.
(Note, this experience was probably 4 or so years ago at this point, things may have matured since then, but I’d still say approach async rails with extreme caution.)
- ioquatix 5y agoNon-blocking Postgres https://github.com/socketry/db-postgres https://github.com/socketry/db-postgres Non-blocking MariaDB https://github.com/socketry/db-mariadb https://github.com/socketry/db-mariadb
- ioquatix 5y agoAlso, it turns out the `pg` is also partially non-blocking. But AR may need to improve their connection pool implementation.
- ninkendo 5y agoDoes DB::Postgres work with ActiveRecord out of the box? The github page doesn’t mention anything about rails/AR. It also doesn’t seem like a super active project…
- ioquatix 5y agoNope, they are totally different. However, the DB gem is an interface/driver similar to PHP's PDO, while AR is a set of drivers, interfaces and high level ORM interfaces. In theory, one could probably use DB as a driver under AR. One person even basically uses AR to generate SQL and then executes it with the DB gem, which I thought was pretty clever.