Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeProvider has a client pool to re-use connections #2527

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

christos-h
Copy link
Contributor

@christos-h christos-h commented Sep 23, 2024

Motivation

Clients are instantiating connections multiple times to validators instead of re-using connections resulting in re-negotiating TLS and general unecessary network overhead.

Proposal

Add a pool of clients to NodeProvider which can be re-used.

This decreases end-to-end operation latency by 10%-35% depending on the RTT between client and committee.

Test Plan

The existing tests will catch regressions. Below are some ad-hoc benchmarks:

RTT: 0.2ms
Transfer Operation (before): 128 ms
Transfer Operation (after): 112 ms

RTT: 50ms
Transfer Operation (before): 1450 ms
Transfer Operation (after): 997 ms

@afck afck self-requested a review September 24, 2024 08:49
@@ -32,14 +39,22 @@ impl ValidatorNodeProvider for NodeProvider {

fn make_node(&self, address: &str) -> anyhow::Result<Self::Node, NodeError> {
let address = address.to_lowercase();
let mut pool = self.client_pool.lock().unwrap();
if let Some(client) = pool.get(&address) {
return Ok(client.clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do both clients handle reconnecting if the other side dropped the connection?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. This needs to be tested

pub struct NodeProvider {
grpc: GrpcNodeProvider,
#[cfg(with_simple_network)]
simple: SimpleNodeProvider,
client_pool: Arc<Mutex<HashMap<String, Client>>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the experience of #2664, the GrpcNodeProvider should instead include a HashMap<String, tonic::transport::Channel>

@afck afck self-requested a review October 23, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants