From 208eeac395079f46fcbe07b4185524e017c554ef Mon Sep 17 00:00:00 2001 From: Pjotr Date: Thu, 8 Oct 2026 11:45:05 +0000 Subject: * src/db.rs (pool): turn off check_health and reset_connection. Each costs a full round trip to the database per pooled checkout (a ping on take, COM_RESET_CONNECTION on return), on top of the query: three round trips per database call instead of one. Against a database about 130 ms away that is 390 ms per call instead of 130 ms. Measured across 25 SQL endpoints: 1.3x (a 15,060-row list, dominated by row cost) to 3.0x (single-call endpoints) faster; the full Rust and Python suites pass. Nothing here needs the reset (queries are read-only and keep no session state). The ping only guarded against a connection the server closed while idle; that now surfaces as a database error on the next query that uses it (the pool then drops it), without a retry. Co-Authored-By: Claude Sonnet 5.5 --- src/db.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/db.rs b/src/db.rs index ee6f494..c6723ff 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,7 +1,7 @@ //! Read-only access to the GeneNetwork MariaDB database (db_webqtl). use mysql::prelude::{FromRow, Queryable}; -use mysql::{params, Opts, Pool}; +use mysql::{params, Opts, OptsBuilder, Pool, PoolOpts}; use serde::Serialize; use std::sync::{Mutex, OnceLock}; @@ -26,13 +26,29 @@ fn sql_uri() -> String { /// around an Option gives the same "build once" behavior while still /// letting a failed attempt be retried on the next call instead of /// wedging into a permanent error. +/// +/// Two defaults are turned off because each costs a full round trip to +/// the database per checkout, on top of the query: `check_health` (a +/// ping when a connection is taken from the pool) and +/// `reset_connection` (a COM_RESET_CONNECTION when it is returned). +/// Together they tripled the cost of every database call against a +/// database about 130 ms away (390 ms instead of 130 ms). Nothing here +/// needs the reset (queries are read-only and keep no session state), +/// and the ping only protects against a connection the server closed +/// while idle -- which would now surface as a database error on the +/// next query using it (the pool then drops that connection). fn pool() -> Result { static POOL: OnceLock>> = OnceLock::new(); let mut guard = POOL.get_or_init(|| Mutex::new(None)).lock().unwrap(); if let Some(pool) = guard.as_ref() { return Ok(pool.clone()); } - let new_pool = Pool::new(Opts::from_url(&sql_uri())?)?; + let opts = OptsBuilder::from_opts(Opts::from_url(&sql_uri())?).pool_opts( + PoolOpts::default() + .with_reset_connection(false) + .with_check_health(false), + ); + let new_pool = Pool::new(opts)?; *guard = Some(new_pool.clone()); Ok(new_pool) } -- cgit 1.4.1