From 311f6246cc2f6eb31d1e9dfeadf49744b1aff7ea Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 2 Jul 2024 18:25:09 +0300 Subject: [PATCH] feat: enable client connection pool + http2 commit-id:7dd63ddc --- crates/mempool_infra/src/component_client.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/mempool_infra/src/component_client.rs b/crates/mempool_infra/src/component_client.rs index 616505c3e..7c536041f 100644 --- a/crates/mempool_infra/src/component_client.rs +++ b/crates/mempool_infra/src/component_client.rs @@ -57,6 +57,7 @@ where Response: for<'a> Deserialize<'a>, { uri: Uri, + client: Client, _req: PhantomData, _res: PhantomData, } @@ -71,7 +72,11 @@ where IpAddr::V4(ip_address) => format!("http://{}:{}/", ip_address, port).parse().unwrap(), IpAddr::V6(ip_address) => format!("http://[{}]:{}/", ip_address, port).parse().unwrap(), }; - Self { uri, _req: PhantomData, _res: PhantomData } + // TODO(Tsabary): Add a configuration for the maximum number of idle connections. + // TODO(Tsabary): Add a configuration for "keep-alive" time of idle connections. + let client = + Client::builder().http2_only(true).pool_max_idle_per_host(usize::MAX).build_http(); + Self { uri, client, _req: PhantomData, _res: PhantomData } } pub async fn send(&self, component_request: Request) -> ClientResult { @@ -83,7 +88,8 @@ where .expect("Request building should succeed"); // Todo(uriel): Add configuration to control number of retries - let http_response = Client::new() + let http_response = self + .client .request(http_request) .await .map_err(|_e| ClientError::CommunicationFailure)?; // Todo(uriel): To be split into multiple errors @@ -102,7 +108,12 @@ where Response: for<'a> Deserialize<'a>, { fn clone(&self) -> Self { - Self { uri: self.uri.clone(), _req: PhantomData, _res: PhantomData } + Self { + uri: self.uri.clone(), + client: self.client.clone(), + _req: PhantomData, + _res: PhantomData, + } } }