perf(http): reuse one reqwest Client instead of building one per request#303
Open
allamiro wants to merge 1 commit into
Open
perf(http): reuse one reqwest Client instead of building one per request#303allamiro wants to merge 1 commit into
allamiro wants to merge 1 commit into
Conversation
A new Client was constructed for every request, defeating connection pooling and TLS session reuse. The client is now created once in Http::new.
2744614 to
bfdd11c
Compare
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.
Fixes #285.
Problem
Http::get_requestbuilt a freshreqwest::Client(its own connection pool and TLS state) for every single request, so nothing was ever reused.Change
The client is created once in
Http::newand stored in the struct;get_requestborrows it.Client::new()panics only on TLS backend initialization failure — same failure mode as before, just at construction.Testing
cargo test: 9/9 pass (the mockito-based HTTP backend tests cover read/write paths).Summary by cubic
Reuse a single
reqwest::Clientacross all HTTP calls to enable connection pooling and TLS session reuse, reducing per-request overhead. The client is now created once inHttp::newand reused byget_request(same TLS init failure behavior, now at construction).Written for commit 2744614. Summary will update on new commits.