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:
charsyam
2013-01-31 12:09:16 +09:00
committed by antirez
parent 14daa01c52
commit 1d80acae54
6 changed files with 30 additions and 2 deletions

View File

@ -382,6 +382,8 @@ void loadServerConfigFromString(char *config) {
if ((server.stop_writes_on_bgsave_err = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"slave-tcp-nodelay-off") && argc == 2) {
server.slave_tcp_nodelay_off = atoi(argv[1]);
} else if (!strcasecmp(argv[0],"slave-priority") && argc == 2) {
server.slave_priority = atoi(argv[1]);
} else if (!strcasecmp(argv[0],"notify-keyspace-events") && argc == 2) {
@ -715,6 +717,10 @@ void configSetCommand(redisClient *c) {
if (flags == -1) goto badfmt;
server.notify_keyspace_events = flags;
} else if (!strcasecmp(c->argv[2]->ptr,"slave-tcp-nodelay-off")) {
if (getLongLongFromObject(o,&ll) == REDIS_ERR ) goto badfmt;
server.slave_tcp_nodelay_off = ll;
} else if (!strcasecmp(c->argv[2]->ptr,"slave-priority")) {
if (getLongLongFromObject(o,&ll) == REDIS_ERR ||
ll <= 0) goto badfmt;
@ -808,6 +814,7 @@ void configGetCommand(redisClient *c) {
config_get_numerical_field("repl-timeout",server.repl_timeout);
config_get_numerical_field("maxclients",server.maxclients);
config_get_numerical_field("watchdog-period",server.watchdog_period);
config_get_numerical_field("slave-tcp-nodelay-off",server.slave_tcp_nodelay_off);
config_get_numerical_field("slave-priority",server.slave_priority);
config_get_numerical_field("hz",server.hz);