Skip to content

Commit 03d49d0

Browse files
committed
http: set TCP_NODELAY when creating HTTP server
Otherwise, the default HTTP server config may result in high latency. [1] https://www.extrahop.com/blog/tcp-nodelay-nagle-quickack-best-practices [2] https://eklitzke.org/the-caveats-of-tcp-nodelay
1 parent 27a770b commit 03d49d0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/httpserver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ static bool HTTPBindAddresses(struct evhttp* http)
388388
if (i->first.empty() || (addr.has_value() && addr->IsBindAny())) {
389389
LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n");
390390
}
391+
// Set the no-delay option (disable Nagle's algorithm) on the TCP socket.
392+
evutil_socket_t fd = evhttp_bound_socket_get_fd(bind_handle);
393+
int one = 1;
394+
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (sockopt_arg_type)&one, sizeof(one)) == SOCKET_ERROR) {
395+
LogInfo("WARNING: Unable to set TCP_NODELAY on RPC server socket, continuing anyway\n");
396+
}
391397
boundSockets.push_back(bind_handle);
392398
} else {
393399
LogPrintf("Binding RPC on address %s port %i failed.\n", i->first, i->second);

0 commit comments

Comments
 (0)