Skip to content

Commit

Permalink
feat(transport): Enable TCP_NODELAY. (#120)
Browse files Browse the repository at this point in the history
The combination of the Nagle algorithm on a client, and delayed ack on a server
can introduce up to 200ms latency if a small gRPC messages is sent with multiple
writes.

Enable TCP_NODELAY to make sure that neither client, nor server buffer their
messages for too long when exchaning small requests.
  • Loading branch information
dominiquelefevre authored and LucioFranco committed Nov 6, 2019
1 parent 23f648b commit 0299509
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tonic/src/transport/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ struct TcpIncoming {

impl TcpIncoming {
fn bind(addr: SocketAddr) -> Result<Self, crate::Error> {
let inner = conn::AddrIncoming::bind(&addr).map_err(Box::new)?;
let mut inner = conn::AddrIncoming::bind(&addr).map_err(Box::new)?;
inner.set_nodelay(true);

Ok(Self { inner })
}
Expand Down
2 changes: 2 additions & 0 deletions tonic/src/transport/service/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tower_service::Service;
pub(crate) fn connector() -> HttpConnector {
let mut http = HttpConnector::new();
http.enforce_http(false);
http.set_nodelay(true);
http
}

Expand All @@ -32,6 +33,7 @@ impl Connector {
pub(crate) fn new(tls: Option<TlsConnector>) -> Self {
let mut http = HttpConnector::new();
http.enforce_http(false);
http.set_nodelay(true);

Self { http, tls }
}
Expand Down

0 comments on commit 0299509

Please sign in to comment.