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
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
Number Of Database ConnectionsPostgreSQL 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
Too many connectionsMySQL When all max_connections are in use, new connections are refused with a Too many connections error
Server Status VariablesMySQL Threads_connected, Threads_running, Connection_errors_max_connections (connections refused because max_connections was reached)