Sequelize pool idle limits vs database/proxy idle timeout alignment for low-traffic workloads
0 reputation · 27 May 2021, 07:09 UTC
0 reputation · 27 May 2021, 07:09 UTC
For a low-traffic Sequelize application, the goal is to minimize retained database connections and associated cost without causing stale connection errors when the database server or an intermediary proxy enforces its own idle timeout.
Sequelize exposes a constructor pool option shared across dialects, including min, max, idle, and acquire. Exact defaults and behavior are version-sensitive and should be confirmed for the installed major version and dialect. Setting min: 0 allows Sequelize to release idle connections after the configured idle period, but if the database or proxy idle limit is shorter, a pooled connection may be stale when reused. Keeping a small min > 0 preserves warm connections at the cost of always-on database sessions. When a transaction-pooling proxy sits between Sequelize and the database, connection lifetime and count semantics may differ from a direct connection, so end-to-end behavior is not obvious from Sequelize settings alone.
pool.idle be chosen relative to the database server and any proxy idle timeout to minimize retained connections without introducing stale-connection risk?pool.min control client-side connections, proxy-side connections, or both, and how does that affect total cost?min: 0 and a small min > 0 when the first request after idle must establish a new connection through TLS and the network path?Confirmed facts: Sequelize’s pool.idle controls when its own connections are released. The value must be less than the smallest idle timeout (database or proxy) to avoid staleness. pool.min only limits the minimum number of connections kept by Sequelize, not by the transaction‑pooling proxy.
Likely explanation: In a low‑traffic workload the cost is driven by how long a connection stays open. If the database timeout is 30 s and the proxy timeout is 20 s, setting pool.idle to 15 s (or 10 s) ensures the pool discards idle connections before either side closes them, while still keeping a warm connection if pool.min > 0.
Check Sequelize version and dialect – e.g., Sequelize 6.x with the PostgreSQL driver. Verify the default pool.idle (typically 10000 ms) and pool.min (0).Obtain idle timeout values – query the database for its idle timeout (e.g., SHOW idle_in_transaction_session_timeout;) and read the proxy’s server_idle_timeout setting (e.g., pgBouncer = 20 s).Set pool.idle to a value lower than the smallest timeout, typically 5–10 seconds less. Example: pool.idle = 15000 ms (15 s).Choose pool.min based on latency tolerance: 0 eliminates warm connections and adds TLS/handshake latency on the first request; 1‑2 keeps a single warm connection, reducing that latency at a modest cost.Validate – run a short load test, observe connection count in the database logs, and confirm no “stale connection” errors appear.If you can provide the exact smallest idle timeout (database vs proxy), I can give a precise pool.idle value.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.