From 2974b7df5b92aa4e360e15eb32c4f65361e8065e Mon Sep 17 00:00:00 2001 From: Yoo1tic <137816438+Yoo1tic@users.noreply.github.com> Date: Sun, 20 Jul 2025 00:46:31 +0800 Subject: [PATCH] feat: optimize reqwest client builder with connection pool size adjustment --- src/config/basic_client.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/config/basic_client.rs b/src/config/basic_client.rs index b3dcf29..1ca5758 100644 --- a/src/config/basic_client.rs +++ b/src/config/basic_client.rs @@ -5,7 +5,13 @@ use reqwest::Client; use crate::config::KeyCheckerConfig; pub fn client_builder(config: &KeyCheckerConfig) -> Result { - let mut builder = Client::builder().timeout(Duration::from_secs(config.timeout_sec)); + // Adjust connection pool size based on concurrency, optimizing for 0.5 second response time + let pool_size = (config.concurrency / 2).max(20).min(config.concurrency); + + let mut builder = Client::builder() + .timeout(Duration::from_secs(config.timeout_sec)) + .pool_max_idle_per_host(pool_size) + .pool_idle_timeout(Duration::from_secs(30)); if let Some(ref proxy_url) = config.proxy { builder = builder.proxy(reqwest::Proxy::all(proxy_url.clone())?);