← Graph

Isolated Reader/Writer Connection Pools

concept 4 connections

Experimental technique demonstrated by Stephen Margheim: abuse Active Record's three-tier multiple-database support to define a `reader` and `writer` configuration that both point to the same SQLite file. The reader pool opens read-only connections (letting SQLite optimize internally and reject writes), while the writer pool is limited to a single connection (moving linear-write serialization from SQLite's file lock up into Active Record where it's faster). A modified database-selector resolver defaults every web request to the reading role ('deferred requests'), and the Active Record `transaction` method is monkey-patched via `prepend` to switch to the writing role for just that operation. Eliminates connection-pool saturation where in-flight writes would starve concurrent reads. Opt-in and marked experimental in the enhanced-sqlite3-adapter gem.

category
pattern
about
Isolated Reader/Writer Connection Pools concept
Experimental fifth performance technique demonstrated via Active Record's multi-database support.
concept Isolated Reader/Writer Connection Pools
related_to
Active Record concept
Built on Active Record's three-tier multi-database support with a custom resolver and a patched transaction method.
concept Isolated Reader/Writer Connection Pools
related_to
Only makes sense because WAL mode allows many concurrent reads alongside the single writer.
related_to
Isolated Reader/Writer Connection Pools concept
Deferred Requests is the request-level switching mechanism that makes isolated pools transparent.

Provenance

Read by
4 extractions