From 99e7e46da1d8478a10e2c7a6419f5e1432b127d0 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 1d5bcd8d4..2fff5e8b7 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) {