From: Stephan Bosch Date: Thu, 16 Jun 2016 20:02:08 +0000 (+0200) Subject: lib-http: client/server: Enable the TCP_NODELAY option for all connections. X-Git-Tag: 2.3.0.rc1~3488 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44005db1cad775e5edf0ea0e88295fa69b5c400f;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client/server: Enable the TCP_NODELAY option for all connections. This disables the TCP Nagle algorithm. With the Nagle algorithm enabled, TCP waits a little to accumulate more data in a small segment before it is sent. For transfer of large continuous payloads, this is not useful and even harmful. If the final remaining bit of the payload is small, the TCP layer will wait for a significant amount of time at the end of the payload. For many sequential transfers, this amounts to much waiting time. This is particularly evident in the test-http-payload test suite tool. Setting TCP_NODELAY decreases its run time from up to 20 minutes to about half a minute my system. --- diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index fed1bba168..9c07f3ec24 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -1195,6 +1195,7 @@ http_client_connection_connected(struct connection *_conn, bool success) conn->connected_timestamp = ioloop_timeval; http_client_connection_debug(conn, "Connected"); + (void)net_set_tcp_nodelay(_conn->fd_out, TRUE); if (set->socket_send_buffer_size > 0) { if (net_set_send_buffer_size(_conn->fd_out, set->socket_send_buffer_size) < 0) diff --git a/src/lib-http/http-server-connection.c b/src/lib-http/http-server-connection.c index ce0ee5be64..34aaf9549c 100644 --- a/src/lib-http/http-server-connection.c +++ b/src/lib-http/http-server-connection.c @@ -1035,6 +1035,8 @@ http_server_connection_create(struct http_server *server, conn->callbacks = callbacks; conn->context = context; + (void)net_set_tcp_nodelay(fd_out, TRUE); + /* get a name for this connection */ if (fd_in != fd_out || net_getpeername(fd_in, &addr, &port) < 0) { name = t_strdup_printf("[%u]", id);