about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-10-08 11:45:05 +0000
committerPjotr <wrk@bosa.lan>2026-10-08 11:55:30 +0000
commit208eeac395079f46fcbe07b4185524e017c554ef (patch)
tree7e1622acd8b2212724d75763201aad2e575c5026 /src
parent22540223c43342473d7d428dffeeab9d94afb55c (diff)
downloadgenenetwork4-208eeac395079f46fcbe07b4185524e017c554ef.tar.gz
* 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 <noreply@anthropic.com>
Diffstat (limited to 'src')
-rw-r--r--src/db.rs20
1 files changed, 18 insertions, 2 deletions
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<Pool, mysql::Error> {
     static POOL: OnceLock<Mutex<Option<Pool>>> = 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)
 }