Skip to content

perf(session): reuse idle HTTP connection pools across sessions - #488

Open
vuanhphung wants to merge 10 commits into
mainfrom
perf/kp-session-client
Open

vuanhphung wants to merge 10 commits into
mainfrom
perf/kp-session-client

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Repeated sessions rebuild reqwest and discard TLS connections. Five rotated fresh-process Node comparisons after the review fixes reduce sequential openSession p50 from 146.63 to 77.02 ms (-47.5%). Earlier driver tracing counted 9→1 TCP connects for nine cycles with auth/session RPC counts unchanged.

Lease cached clients exclusively so active sessions retain independent idle caps and request locality. Authentication, headers, retries and telemetry remain session-local. HttpConfig::reuse_client_across_sessions = false opts out while preserving within-session keep-alive. This is a Rust HTTP-config option; exposing it in bindings is a follow-up. Reuse is default-on, bounded to 16 idle clients/runtime, 90s idle plus a 15s cleanup sweep while the runtime is driven (next access/shutdown otherwise), and 300s maximum client age. Cache access sweeps expired entries too; the transport key exhaustively classifies client settings. This composes with #453/#455/#459/#470.

Verification: fmt/native/rustls clippy, workspace excluding existing U2M failures, 161 rustls client, 91 napi, 31 PyO3 Rust, 58 live Python, 34 Node e2e, 30 live SEA and 96 pool stress processes pass; 4 Node cases remain pending. Three unfiltered local U2M failures reproduce on the baseline. Session-reuse, expiry and opt-out mutants fail assertions/exit101; adding a client-config field fails compilation with E0027.

Scenario #434 baseline p50 / p95 / p99 ms branch p50 / p95 / p99 ms
Live sequential open 146.63 / 177.02 / 205.48 77.02 / 109.22 / 169.17
Live burst10 open 146.31 / 191.62 / 255.54 81.11 / 161.23 / 206.46
Live burst50 open 155.70 / 186.96 / 202.14 158.29 / 184.94 / 208.98
Mock 8×16 CloudFetch steady round 174.84 / 209.61 / 209.61 178.04 / 244.84 / 244.84

The 8×16 mock has zero reconnects in all 15 steady rounds/side and matching value/null checksums. Live auth is CLI OAuth; PAT/M2M coverage is mocked. No statement-throughput gain is claimed. Earlier unfavorable CloudFetch/tail results and Python/idle/M2M evidence remain archived. CI's unchanged chrono advisory failures are documented.

Adversarial review converged in round 2 with no open high; R2-1–R2-4 are fixed in separate signed-off commits with tests and mutant evidence. Rebased onto main after #434 merged; the tree is identical to the bot-approved 57a6bbf.

This pull request and its description were written by Isaac.

@vuanhphung vuanhphung changed the title perf(session): reuse HTTP connection pools across sessions perf(session): reuse idle HTTP connection pools across sessions Nov 20, 2026
@vuanhphung
vuanhphung force-pushed the perf/kp-session-client branch from f043a8e to d0f5034 Compare November 20, 2026 03:39

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Medium · 1 Low

Looks good, with one low-severity changelog duplicate. The pool key covers every client config field (checked by an exhaustive destructure). The reqwest client has no cookies and no default headers, so auth and custom headers stay per-session. Lock ordering and shutdown/close handling look sound.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • 🟡 Medium — The bindings inherit default-on reuse but do not expose its keep-alive-preserving opt-out, so Node/C callers cannot request fresh transport/trust state per session without disabling pooling or altering TLS configuration. Expose the boolean through the binding configuration surfaces and generated declarations, with mapping tests and retention documentation. (Found by GPT-6.1 Sol · the judge couldn't confirm it)

Comment thread NEXT_CHANGELOG.md Resolved
@vuanhphung

Copy link
Copy Markdown
Collaborator Author

On the binding suggestion in the review body: the approved scope explicitly says, “No binding needs to expose it in this PR.” HttpConfig::reuse_client_across_sessions = false provides the requested kernel opt-out, tested to preserve within-session keep-alive. The default-on policy and its 90+15 s / 300 s bounds are intentional and documented; bindings keep that default. Exposing this setting through Node/Python/C configuration is a follow-up with mapping tests, outside this approved change.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Medium · 1 Low

Looks good, with 2 low concerns. The pool key correctly separates transport settings from per-request ones (headers, org_id and auth are all applied per request). Leasing, expiry and shutdown are well covered by tests.

Comment thread src/client/pool.rs Resolved
Comment thread src/config.rs Resolved

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Nit

Looks good, with 1 low concern. The leasing, expiry, registry and shutdown paths look sound. The Weak transport fix in the reader factory and its release test are correct.

Other findings

  • ⚪ Nit — PoolKey::new does a blocking std::fs::read and SHA-256 of SSL_CERT_FILE on every pooled Session::open, on an async worker thread. The impact is small: it only runs when SSL_CERT_FILE is set, bundles are usually a few hundred KB, and the client build already does blocking work. If it matters, cache the digest by path, mtime and length, or run it in spawn_blocking. (Found by Claude Opus 5.5 · confirmed by the judge)

@vuanhphung

Copy link
Copy Markdown
Collaborator Author

The fingerprint nit repeats F2, already accepted and resolved at this head: #488 (comment). Content hashing preserves trust-byte identity; path/mtime/length can miss replacements. The existing synchronous TLS-build path remains a separate offload follow-up, with the cold-miss extra read recorded in the evidence.

vuanhphung and others added 9 commits November 22, 2026 19:22
Keep authentication, retries and session state independent while sharing
reqwest clients for matching host, transport configuration and runtime.
Expire idle clients and bound retention across runtimes and configurations.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Preserve per-session idle-socket limits and request locality by returning clients only after their HTTP wrapper is dropped. Bound total client age, retain runtime shutdown safety, and isolate socket/configuration tests from connection-establishment races.

Address adversarial review R1-1 through R1-9; declare Tokio 1.49 for runtime IDs and document bounded TLS/proxy retention.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Cover the Session::open wiring with eight sequential opens and request-used socket IDs, tolerating spare connects. Replacing for_session with new fails the test with exit 101.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Destructure HttpClientConfig exhaustively, requiring new settings to be classified before compilation succeeds. Test per-request settings independently; adding a future transport field fails with E0027 in TransportKey::from.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Sweep all expired entries on take and put, including rejected returns, and drop them after unlocking. Test a current-thread runtime that is never polled; removing either sweep fails the test.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Add HttpConfig::reuse_client_across_sessions, defaulting to true. False bypasses only the cross-session cache and preserves within-session keep-alive. Document idle/trust retention and test both behaviors, including two failing mutants.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Keep the original entry from #434 and remove this branch duplicate. Verified that exactly one transport-cycle entry remains and the reuse opt-out documentation is preserved.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Document the Rust-only opt-out and idle/trust retention in Node/Python release notes, the shared C ABI connection reference and ADBC configuration docs. Validate all five documents name the option and bounds; no runtime or binding API change.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 2 Low

Looks good, with 2 low concerns. The transport key covers every builder input, headers and compression stay per-request, and the lease and lock ordering look sound.

Comment thread src/client/pool.rs
impl PoolKey {
fn new(host: &str, config: &HttpClientConfig) -> Option<Self> {
let root_file = match std::env::var_os("SSL_CERT_FILE") {
Some(path) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — PoolKey::new runs a blocking std::fs::read plus SHA-256 of the whole SSL_CERT_FILE on every Session::open, from async code, even on a cache hit. Cache the digest by path plus mtime/len, or use spawn_blocking.

🔀 Found by Claude Opus 5.5 · confirmed by the judge

Comment thread src/client/pool.rs
Self {
connect_timeout: *connect_timeout,
read_timeout: *read_timeout,
max_connections_per_host: *max_connections_per_host,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The pool key clones tls.client_key_pem and proxy.password in plaintext and keeps them in idle cache entries for up to about 105s after the session ends. They are not zeroized, and the cache outlives the session config that held them. Store a hash of the secret fields in the key, or zeroize on eviction.

🔀 Found by Claude Opus 5.5 · confirmed by the judge

Resolve the main changes by merging (no force-push).

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 2 low concerns. The pool key covers every reqwest builder setting, the lock order is consistent, shutdown closes the cache, and tests cover reuse, partitioning, expiry and opt-out.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.

🔀 1 finding considered and dismissed by the judge
  • 🔵 Low src/client/http.rs:116 — Deriving PartialEq, Eq on the public ProxyConfig/TlsConfig commits the crate to a new public trait surface. These types hold proxy passwords and client pr
    Judge's evidence: #[derive(Clone, Default, PartialEq, Eq)] pub struct TlsConfig {

Comment thread src/client/pool.rs
fn new(host: &str, config: &HttpClientConfig) -> Option<Self> {
let root_file = match std::env::var_os("SSL_CERT_FILE") {
Some(path) => {
let contents = std::fs::read(&path).ok()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — PoolKey::new does a blocking std::fs::read and SHA-256 of SSL_CERT_FILE on the async worker thread for each pooled session open (only when that variable is set). Cache the digest by path/mtime/len or use spawn_blocking.

🔀 Found by Claude Opus 5.5 · confirmed by the judge

This branch was previously deployed

1 inactive deployment
azure-prod — 1aec75a0 Deployed Nov 24, 2026 by oss-reviewer-bot[bot] via followup #4243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant