diff --git a/crates/notary/client/src/client.rs b/crates/notary/client/src/client.rs index 7fb8cda31..a3f15ad86 100644 --- a/crates/notary/client/src/client.rs +++ b/crates/notary/client/src/client.rs @@ -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 { + 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 { diff --git a/crates/notary/server/src/server.rs b/crates/notary/server/src/server.rs index 3eeb38c0e..456272fa1 100644 --- a/crates/notary/server/src/server.rs +++ b/crates/notary/server/src/server.rs @@ -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();