perf(init): parallelize init HTTP client construction#1282
Draft
duncanista wants to merge 1 commit into
Draft
Conversation
Build the register/`/next` reqwest client on a blocking thread inside a spawned task so its native-cert-loading TLS build (and the register network round-trip) overlaps with config parsing and the shared flushing client build, instead of running serially during cold start. The register/`/next` client and the shared flushing client are kept separate on purpose and not collapsed: the Extension API register + `/next` long-poll must use `.no_proxy()` and carry no `flush_timeout` (which would abort the long-poll), while the shared client requires proxy support, a flush_timeout, and pool_max_idle_per_host(0). Those needs conflict, so their construction is overlapped rather than merged. All existing client settings and the cold-start init checkpoints are preserved.
|
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Cold-start optimization (Confluence H4). During init,
main.rsbuilds two reqwest clients whose TLS construction loads native root certificates:/nextclient (built viacreate_reqwest_client_builder()…no_proxy().build()), andbottlecap::http::get_client, used for metrics / logs / trace-proxy / Datadog API calls).Previously these two builds ran serially. This PR overlaps them: the register/
/nextclient is now built on a blocking thread (spawn_blocking) inside a spawned task, and the extensionregisternetwork round-trip runs there too — so both the second cert load and the register call overlap with config parsing and the shared client build on the main task.Approach: parallelize, not merge
I deliberately did not collapse the two clients into one. Their requirements genuinely conflict:
/nextclientDD_PROXY_HTTPS).no_proxy()) — Runtime API is localflush_timeout/nextis a long-poll that blocks until the next invocation; a timeout would abort ittimeout(flush_timeout)pool_max_idle_per_host(0)(issue #1092 stale-conn fix)Because a flush timeout and the proxy would both break the
/nextlong-poll, merging is not behavior-safe. So I took the fallback: build the two clients concurrently instead.Preserved settings / behavior
bottlecap::http::get_client(&config)→ keepsflush_timeout,pool_max_idle_per_host(0), proxy, http2/http1 selection, and custom-cert unchanged./nextclient still built viacreate_reqwest_client_builder()…no_proxy().build()(no proxy, no timeout); it is handed back from the task and reused for the/nextlong-poll for the extension's lifetime — same as before.clippy.tomldisallowed-methodsrespected — no directreqwest::Client::builder; still uses the FIPS adapter /get_client.tls_client_buildcheckpoint is folded into the parallel build phase (it is no longer a distinct serial step);crypto_provider_ready→config_parse→shared_client_ready→register_readyremain sequential and meaningful.Files changed:
bottlecap/src/bin/bottlecap/main.rs(init section only).Testing
cargo fmtclean.cargo clippy --bin bottlecap --no-depsclean (clippy::all + pedantic +unwrap_useddenied); only the pre-existingbuf_redux/multipartfuture-incompat warning remains.extension_loop_active/extension_loop_idle) are unchanged; the register//nextclient is the same one, just built concurrently and returned from the task.Jira: none yet — add before marking ready.