mirror of
https://github.com/element-hq/synapse.git
synced 2026-11-04 22:07:34 +00:00
Each connection of the native pool caches its prepared statements, and a statement it has not prepared costs an extra round trip. Two things made those misses common: - The pool handed out connections in rotation (deadpool's default FIFO queue), so each statement was prepared on every connection in turn, and idle connections were as likely to be picked as busy ones. - A full cache was emptied whole, so one burst of one-off SQL re-cost the whole hot set. The pool now hands out the most recently returned connection first (LIFO), so the connections that do the work keep warm caches, and a full cache drops its least recently used statement. The clear counter becomes `synapse_rust_db_pool_statement_cache_evictions_total`. With five warm-up rooms, the E2EE monitor's room goes from 135 to 102 round trips. With LIFO, connections at the back of the pool can sit idle for long stretches. A server-side close is caught at checkout by the liveness check, but a firewall that silently drops an idle flow is only noticed through TCP keepalives, which tokio-postgres enables by default, as libpq does for psycopg2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVLsNh6akt4ifEizY4D1ta