Skip to content

Commit

Permalink
feat: enable client connection pool + http2
Browse files Browse the repository at this point in the history
commit-id:7dd63ddc
  • Loading branch information
Itay-Tsabary-Starkware committed Jul 3, 2024
1 parent e2a3b42 commit 311f624
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions crates/mempool_infra/src/component_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ where
Response: for<'a> Deserialize<'a>,
{
uri: Uri,
client: Client<hyper::client::HttpConnector>,
_req: PhantomData<Request>,
_res: PhantomData<Response>,
}
Expand All @@ -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<Response> {
Expand All @@ -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
Expand All @@ -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,
}
}
}

Expand Down

0 comments on commit 311f624

Please sign in to comment.