Skip to content

Commit

Permalink
lib-http: client/server: Enable the TCP_NODELAY option for all connec…
Browse files Browse the repository at this point in the history
…tions.

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.
  • Loading branch information
stephanbosch authored and sirainen committed Nov 9, 2016
1 parent a2f8d56 commit 3a939e6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib-http/http-client-connection.c
Expand Up @@ -1253,6 +1253,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)
Expand Down
1 change: 1 addition & 0 deletions src/lib-http/http-server-connection.c
Expand Up @@ -1072,6 +1072,7 @@ http_server_connection_create(struct http_server *server,
i_error("net_set_recv_buffer_size(%"PRIuSIZE_T") failed: %m",
set->socket_recv_buffer_size);
}
(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) {
Expand Down

0 comments on commit 3a939e6

Please sign in to comment.