한국어English日本語简体中文繁體中文DeutschไทยTiếng ViệtРусскийPortuguês (Brasil)EspañolBahasa Indonesia

Game Lag White Paper › L12 Database

Connection pool exhaustion Connection pool exhaustion

Cause ID db-pool · Primary owner Game team (Server development) · Also Infra team (DB infrastructure)

Open the interactive card with figures and simulations →

The number of connections open to the DB is fixed, so when slow queries hold connections, every other request waits.

Why Slow queries or a flood of requests put every connection in use → Effect New requests wait until a connection frees up → On screen Infinite loading at login, slow saves, timeouts

Symptoms
Can’t connect / infinite loading, Input lag
Factors
Stall, Latency
Who’s affected
Whole server, One feature only
When
Right after login or maintenance, When crowds gather
Owner
Primary owner Game team (Server development) · Also Infra team (DB infrastructure)
Game team action items
Remove slow queries, tune pool size and wait timeout (don’t just keep growing the pool), separate pools per feature.
Infra team action items
Check the DB’s max connections and CPU/IOPS headroom, confirm that server count × pool size stays within max connections before adding servers or autoscaling, add connection wait and lock wait metrics to monitoring.
Ballpark numbers
Estimate the connections you need as “requests per second × time each request holds a connection”. At 2,000 requests a second and 5 ms each, 10 connections are busy on average at all times. To handle bursts, pools are usually sized at two to three times that. If queries slow to 150 ms, the same load needs 300.
On the graph
Hits a ceiling · DB connections in use, connection wait time
Where to look
Count connection states per game server on the DB side. MySQL: Host, Command (Sleep for idle connections), and Time in SHOW PROCESSLIST, plus Threads_connected, Threads_running, and refused connections in Connection_errors_max_connections. PostgreSQL: pg_stat_activity grouped by client_addr and state. If the game server’s connection pool library exports wait count and wait time, view those too
Confirmed if
All of one game server’s connections, up to the pool size, are running queries with 0 idle, and logins and saves wait meanwhile. Or the DB’s total connection count hits max_connections and new connections are refused
Ruled out if
Slow even with plenty of idle connections: latency of the queries themselves (db-no-index, db-hot-row) or saturated DB resources
Check with
Infra tools (no game code needed)
Learn more
Blindly growing the pool only adds DB CPU load and lock contention, and everyone slows down together. Also, if server count × pool size exceeds the DB’s max connections, newly added or restarted servers can’t even open a connection. This is common right after autoscaling or maintenance.

Sources

  1. Number Of Database Connections PostgreSQL
    Once DB resources are fully used, adding connections actually lowers throughput; matching active connections to resources and queueing the rest gives better latency and throughput
  2. Too many connections MySQL
    When all max_connections are in use, new connections are refused with a Too many connections error
  3. Connections and Authentication (PostgreSQL Documentation) PostgreSQL
    max_connections: cap on concurrent connections, usually 100 by default
  4. SHOW PROCESSLIST Statement MySQL
    Host (client address), Command (Sleep for idle sessions), Time, State
  5. Server Status Variables MySQL
    Threads_connected, Threads_running, Connection_errors_max_connections (connections refused because max_connections was reached)
  6. The Cumulative Statistics System (PostgreSQL Documentation) PostgreSQL
    pg_stat_activity: client_addr and state (active, idle, idle in transaction, and so on) for each connection

See also

Same layer: L12 Database

Same symptom (Can’t connect / infinite loading), other layers

View the interactive card with figures and simulations