-
Notifications
You must be signed in to change notification settings - Fork 159
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>>>, |
There was a problem hiding this comment.
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>
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: