broker: make Postgres pool size configurable, bump default 5 → 8

Under concurrent door executions the broker was queueing on its 5-connection
pool, adding latency to tool calls that fanned out from the same run. Bump
the default to 8 (one connection per concurrent door before queueing) and
expose CLAWMATES_BROKER_POOL_SIZE so the fleet can tune it up as the load
grows without a rebuild.
This commit is contained in:
Omar Sobh
2026-07-05 18:49:17 -07:00
parent e2c82d9a93
commit 3b382d659a
+8 -1
View File
@@ -6,6 +6,7 @@
//! - `CLAWMATES_DATABASE__URL` Postgres connection string (required) //! - `CLAWMATES_DATABASE__URL` Postgres connection string (required)
//! - `CLAWMATES_BROKER_SOCKET` unix socket path (default /tmp/clawmates-broker.sock) //! - `CLAWMATES_BROKER_SOCKET` unix socket path (default /tmp/clawmates-broker.sock)
//! - `CLAWMATES_BROKER_KEY_FILE` master key file; generated on first boot //! - `CLAWMATES_BROKER_KEY_FILE` master key file; generated on first boot
//! - `CLAWMATES_BROKER_POOL_SIZE` max Postgres connections (default 8)
use std::path::PathBuf; use std::path::PathBuf;
use std::process::ExitCode; use std::process::ExitCode;
@@ -45,7 +46,13 @@ async fn run() -> Result<(), String> {
} }
let key = FileKey::load(&key_path).map_err(|e| format!("key load failed: {e}"))?; let key = FileKey::load(&key_path).map_err(|e| format!("key load failed: {e}"))?;
let pool = cm_db::connect(&database_url, 5) // Pool size defaults to 8: one broker connection per concurrent door
// execution before we start queueing. Tune via env when the fleet grows.
let pool_size: u32 = std::env::var("CLAWMATES_BROKER_POOL_SIZE")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(8);
let pool = cm_db::connect(&database_url, pool_size)
.await .await
.map_err(|e| format!("database connection failed: {e}"))?; .map_err(|e| format!("database connection failed: {e}"))?;