fix: set TCP_NODELAY for prover and notary (#911)

This commit is contained in:
dan
2025-06-10 08:13:12 +00:00
committed by GitHub
parent bc1eba18c9
commit 55091b5e94
2 changed files with 15 additions and 9 deletions

View File

@@ -30,7 +30,7 @@ use tokio_rustls::{
rustls::{self, ClientConfig, OwnedTrustAnchor, RootCertStore},
TlsConnector,
};
use tracing::{debug, error};
use tracing::{debug, error, info};
use crate::error::{ClientError, ErrorKind};
@@ -178,6 +178,15 @@ impl NotaryClient {
&self,
notarization_request: NotarizationRequest,
) -> Result<Accepted, ClientError> {
let notary_socket = tokio::net::TcpStream::connect((self.host.as_str(), self.port))
.await
.map_err(|err| ClientError::new(ErrorKind::Connection, Some(Box::new(err))))?;
// Setting TCP_NODELAY will improve prover latency.
let _ = notary_socket
.set_nodelay(true)
.map_err(|_| info!("An error occured when setting TCP_NODELAY. This will result in higher protocol latency."));
if self.tls {
debug!("Setting up tls connection...");
@@ -186,10 +195,6 @@ impl NotaryClient {
.with_root_certificates(self.root_cert_store.clone())
.with_no_client_auth();
let notary_socket = tokio::net::TcpStream::connect((self.host.as_str(), self.port))
.await
.map_err(|err| ClientError::new(ErrorKind::Connection, Some(Box::new(err))))?;
let notary_connector = TlsConnector::from(Arc::new(notary_client_config));
let notary_tls_socket = notary_connector
.connect(
@@ -216,10 +221,6 @@ impl NotaryClient {
} else {
debug!("Setting up tcp connection...");
let notary_socket = tokio::net::TcpStream::connect((self.host.as_str(), self.port))
.await
.map_err(|err| ClientError::new(ErrorKind::Connection, Some(Box::new(err))))?;
self.send_request(notary_socket, notarization_request)
.await
.map(|(connection, session_id)| Accepted {

View File

@@ -181,6 +181,11 @@ pub async fn run_server(config: &NotaryServerProperties) -> Result<(), NotarySer
continue;
}
};
// Setting TCP_NODELAY will improve notary latency.
let _ = stream.set_nodelay(true).map_err(|_| {
info!("An error occured when setting TCP_NODELAY. This will result in higher protocol latency.");
});
debug!("Received a prover's TCP connection");
let tower_service = router.clone();