Skip to content

perf(client): skip reqwest's per-request retry copy; reuse the Authorization value - #470

Open
vuanhphung wants to merge 3 commits into
mainfrom
perf/rd-request-overhead
Open

vuanhphung wants to merge 3 commits into
mainfrom
perf/rd-request-overhead

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

On a Real-Time warehouse each query is two HTTP requests (ExecuteStatement, then CloseStatement), so per-request client CPU counts twice. A profile of one Python process running SELECT 1 on 800 threads shows two avoidable costs on every request:

  • reqwest's default retry layer copies the whole request (headers, URI, extensions, body) before sending it, so it can replay HTTP/2 or HTTP/3 refusals. The kernel builds reqwest without either protocol and does its own retries in execute_impl, so the copy is never used.
  • The Authorization value is rebuilt per request: the provider's string is validated into a new HeaderValue, and with token federation (the wrapper around a PAT) the JWT is base64- and JSON-decoded and its issuer URL parsed to decide whether it needs exchange.

Fix

The client sets retry(never().max_retries_per_request(0)). The validated Authorization value and the federation issuer decision are remembered for the exact header string, so an unchanged token reuses them and any new token is checked again. The cached value is marked sensitive and Debug never prints it.

Verification

cargo fmt, cargo clippy --all-targets -D warnings and cargo test pass; new tests auth_value_cache_reuses_the_value_until_the_header_changes and issuer_decision_follows_the_current_token.

Python driver end to end, SELECT 1 back to back in one process, on the full factory stack (#453 #455 #456 #457 #458 #459 #461 #467 #468 #469) with and without this change. Mock: a TLS server replaying the live Real-Time response bytes and headers (execute 80 ms, close 60 ms), a JWT-shaped token, client on 6 cores, 3 interleaved runs, medians:

1 process × 800 threads before this PR
client CPU / query 0.359 ms 0.349 ms (-2.8%)
steady QPS 9,039 9,049

Live, staging X-Large Real-Time warehouse, 8 client cores, one run each: an env-gated prototype of this change together with the close-path change in #472 (same code paths) cut client CPU per query at 1 process × 800 threads from 0.433 to 0.405 ms (-6.5%); steady QPS 7,651 → 7,961 and query p99 249 → 220 ms (that load is round-trip bound). Live, Medium Real-Time warehouse (server-bound at about 860 QPS), 1 × 200 threads, 60 s, 2 interleaved rounds, the exact commits of this PR, #472 and #471 together: 0.398 → 0.386 ms CPU per query, same QPS, same server-side error counts.

This pull request and its description were written by Isaac.

…ke; reuse the Authorization value

reqwest's default retry layer clones each request (headers, URI,
extensions, body) so it can replay HTTP/2 and HTTP/3 refusals. This
client speaks HTTP/1.1 only and execute_impl does the kernel's retries,
so the layer is turned off.

The validated Authorization header value is reused while the provider
returns the same string, and FederationProvider decides whether a
token's issuer is foreign once per distinct token instead of decoding
the JWT and parsing its issuer URL on every request.

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

Verdict: 1 Low · 1 Nit

Looks good: two low-severity notes. The reqwest retry-disable and the per-header caches are correct, keep re-checking the issuer when the token rotates, and keep the credential out of Debug.

Other findings

  • ⚪ Nit — get_or_build takes an exclusive std::sync::Mutex on every authenticated request, including when the cache is hit, and holds it while comparing the full token string. The PR is aimed at 800-thread loads, so all of those requests now pass through one lock. The critical section is small, but an RwLock read lock for the hit path (the same pattern FederationProvider::token_is_foreign uses), taking the write lock only on a miss, would remove the serialization the cache adds. Worth checking against the profile.

Comment thread src/client/http.rs Resolved
…:retry

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

Verdict: 1 Low

Looks good, with one low-severity contention concern. Disabling reqwest's built-in retry fits with the kernel doing its own retries in execute_impl, and caching the Authorization value and federation issuer decision by the exact header string correctly re-checks any new token. Both caches are redacted in Debug.

Comment thread src/client/http.rs Resolved
Requests that share a token now only take the read side, so concurrent requests don't serialize on the cache; the write lock is taken only when the provider returns a new header.

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

✅ No issues identified by the review bot.

This branch was previously deployed

1 inactive deployment
azure-prod — d43d3e46 Deployed Nov 15, 2026 by oss-reviewer-bot[bot] via followup #3189
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