Skip to content

Commit

Permalink
v1.17: Limit max concurrent connections (backport of #851) (#925)
Browse files Browse the repository at this point in the history
* Limit max concurrent connections (#851)


Co-authored-by: Lijun Wang <[email protected]>
  • Loading branch information
2 people authored and yihau committed Apr 27, 2024
1 parent e37db79 commit 4ed2a77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion streamer/src/nonblocking/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ pub fn spawn_server(
coalesce: Duration,
) -> Result<(Endpoint, Arc<StreamStats>, JoinHandle<()>), QuicServerError> {
info!("Start {name} quic server on {sock:?}");
let (config, _cert) = configure_server(keypair, gossip_host)?;
let concurrent_connections = max_staked_connections + max_unstaked_connections;
let max_concurrent_connections = concurrent_connections + concurrent_connections / 4;
let (config, _cert) = configure_server(keypair, gossip_host, max_concurrent_connections)?;

let endpoint = Endpoint::new(
EndpointConfig::default(),
Expand Down
2 changes: 2 additions & 0 deletions streamer/src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl rustls::server::ClientCertVerifier for SkipClientVerification {
pub(crate) fn configure_server(
identity_keypair: &Keypair,
gossip_host: IpAddr,
max_concurrent_connections: usize,
) -> Result<(ServerConfig, String), QuicServerError> {
let (cert, priv_key) = new_self_signed_tls_certificate(identity_keypair, gossip_host)?;
let cert_chain_pem_parts = vec![Pem {
Expand All @@ -71,6 +72,7 @@ pub(crate) fn configure_server(
server_tls_config.alpn_protocols = vec![ALPN_TPU_PROTOCOL_ID.to_vec()];

let mut server_config = ServerConfig::with_crypto(Arc::new(server_tls_config));
server_config.concurrent_connections(max_concurrent_connections as u32);
server_config.use_retry(true);
let config = Arc::get_mut(&mut server_config.transport).unwrap();

Expand Down

1 comment on commit 4ed2a77

@hawkins65
Copy link

Choose a reason for hiding this comment

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

What other type of connection is there besides staked and unstaked to end up at max_concurrent = 1.25 * (max_staked + max_unstaked)

Please sign in to comment.