Skip to main content

Module pool

Module pool 

Source
Expand description

Database connections, opened once and kept.

Every read used to open its own: a connection, a permissions syscall, the whole schema DDL and a WAL checkpoint, before a single row came back. Clicking an album paid all of it, and while downloads were writing, the checkpoint contended with them and it took seconds.

A pool rather than one shared connection, because rusqlite’s Connection is Send but not Sync: sharing one means a mutex, and a mutex means every read waits for every other. SQLite in WAL mode reads concurrently across connections, so the way to keep that is to have several and hand them out.

A connection is opened only when every existing one is busy, so the pool grows to whatever concurrency actually happens. What it keeps is capped: queueing a thousand tracks runs as many transfers at once as download_workers allows and no more, but a burst wider than the cap should not leave a thousand connections parked for the rest of the session, each holding its own page cache. Past the cap a returned connection is closed rather than kept.

Structs§

Handle
A borrowed connection, returned to the pool when it goes out of scope.
Pool

Functions§

shared
The process’s pool for the default library.