From fd8efb7c3615f1a0c78a03388d5b18bc9c4049f8 Mon Sep 17 00:00:00 2001 From: Guy Benoish Date: Mon, 6 Mar 2017 18:42:52 +0200 Subject: [PATCH] Replication buffer fills up on high rate traffic. When feeding the master with a high rate traffic the the slave's feed is much slower. This causes the replication buffer to grow (indefinitely) which leads to slave disconnection. The problem is that writeToClient() decides to stop writing after NET_MAX_WRITES_PER_EVENT writes (In order to be fair to clients). We should ignore this when the client is a slave. It's better if clients wait longer, the alternative is that the slave has no chance to stay in sync in this situation. --- src/networking.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/networking.c b/src/networking.c index 1d5bcd8d..2fff5e8b 100644 --- a/src/networking.c +++ b/src/networking.c @@ -972,10 +972,15 @@ int writeToClient(int fd, client *c, int handler_installed) { * scenario think about 'KEYS *' against the loopback interface). * * However if we are over the maxmemory limit we ignore that and - * just deliver as much data as it is possible to deliver. */ + * just deliver as much data as it is possible to deliver. + * + * Moreover, we also send as much as possible if the client is + * a slave (otherwise, on high-speed traffic, the replication + * buffer will grow indefinitely) */ if (totwritten > NET_MAX_WRITES_PER_EVENT && (server.maxmemory == 0 || - zmalloc_used_memory() < server.maxmemory)) break; + zmalloc_used_memory() < server.maxmemory) && + !(c->flags & CLIENT_SLAVE)) break; } server.stat_net_output_bytes += totwritten; if (nwritten == -1) {