mirror of
https://github.com/fluencelabs/redis
synced 2025-06-12 16:51:22 +00:00
Turn off TCP_NODELAY on the slave socket after SYNC.
Further details from @antirez: It was reported by @StopForumSpam on Twitter that the Redis replication link was strangely using multiple TCP packets for multiple commands. This wastes a lot of bandwidth and is due to the TCP_NODELAY option we enable on the socket after accepting a new connection. However the master -> slave channel is a one-way channel since Redis replication is asynchronous, so there is no point in trying to reduce the latency, we should aim to reduce the bandwidth. For this reason this commit introduces the ability to disable the nagle algorithm on the socket after a successful SYNC. This feature is off by default because the delay can be up to 40 milliseconds with normally configured Linux kernels.
This commit is contained in:
@ -118,6 +118,14 @@ void syncCommand(redisClient *c) {
|
||||
/* ignore SYNC if already slave or in monitor mode */
|
||||
if (c->flags & REDIS_SLAVE) return;
|
||||
|
||||
if (server.slave_tcp_nodelay_off) {
|
||||
redisLog(REDIS_NOTICE, "Turning off slave's :%d TCP NODELAY SETTING", c->fd);
|
||||
char err[1024];
|
||||
if (anetTcpNoDelayOff(err, c->fd) == ANET_ERR)
|
||||
redisLog(REDIS_WARNING,
|
||||
"Can't turn off %d 's tcp nodelay setting: %s", c->fd, err);
|
||||
}
|
||||
|
||||
/* Refuse SYNC requests if we are a slave but the link with our master
|
||||
* is not ok... */
|
||||
if (server.masterhost && server.repl_state != REDIS_REPL_CONNECTED) {
|
||||
|
Reference in New Issue
Block a user