diff --git a/napi/src/database.rs b/napi/src/database.rs index b94cafcc..d2b8fac4 100644 --- a/napi/src/database.rs +++ b/napi/src/database.rs @@ -28,7 +28,21 @@ use std::collections::HashMap; use std::sync::Arc; use tokio::sync::Mutex; -use databricks_sql_kernel::{AuthConfig, DefaultOpts, Session}; +use databricks_sql_kernel::{AuthConfig, DefaultOpts, HttpConfig, Session}; + +/// NodeJS-driver-appropriate default for `pool_max_idle_per_host`. +/// +/// Applied by [`open_session`] when the JS caller does not pass +/// `maxConnections`. Matches the JDBC driver's `HttpConnectionPoolSize` +/// default (100) and closes the throughput gap vs the NodeJS Thrift +/// driver's `maxSockets: Infinity` pool for bursty workloads +/// (concurrent `executeStatement`, parallel CloudFetch chunk downloads). +/// +/// The kernel core's [`HttpConfig::pool_max_idle_per_host`] default +/// remains at the conservative kernel value (10) — each binding +/// chooses its own user-facing default. The pyo3 binding inherits +/// the kernel default; this constant is napi-specific. +pub const NAPI_DEFAULT_POOL_MAX_IDLE_PER_HOST: usize = 100; use crate::connection::Connection; use crate::error::napi_err_from_kernel; @@ -70,6 +84,27 @@ pub struct ConnectionOptions { /// query-tag presets, …). Forwarded verbatim to SEA /// `session_confs`. Unknown keys are rejected server-side. pub session_conf: Option>, + /// Maximum number of pooled HTTP connections per host. Routes + /// through the kernel's [`HttpConfig::pool_max_idle_per_host`]. + /// Tunes the underlying `reqwest` connection pool — higher values + /// reduce reconnect overhead when many statements run + /// concurrently against the same warehouse. + /// + /// When the JS caller does NOT provide `maxConnections`, the napi + /// binding applies a NodeJS-driver-appropriate default of + /// [`NAPI_DEFAULT_POOL_MAX_IDLE_PER_HOST`] (100) — chosen to match + /// the JDBC driver's `HttpConnectionPoolSize` default and to close + /// the throughput gap vs the NodeJS Thrift driver's + /// `maxSockets: Infinity` pool for bursty workloads. The kernel + /// core's [`HttpConfig::pool_max_idle_per_host`] default remains + /// at the conservative kernel value (10); each binding chooses + /// its own user-facing default. Mirrors the Python connector's + /// `max_connections` kwarg on the SEA backend, which exposes the + /// knob but keeps its own urllib3-aligned default of 10. + /// + /// Napi-rs serialises `u32` as JS `number`; values up to + /// `2^32 - 1` round-trip safely (any reasonable pool size fits). + pub max_connections: Option, } /// Open a Databricks SQL session over PAT auth and return an opaque @@ -115,6 +150,19 @@ pub async fn open_session(options: ConnectionOptions) -> napi::Result