From 2248eaacac991a851c55dbb33bc328b7d6f780a8 Mon Sep 17 00:00:00 2001 From: "zhaozhao.zz" Date: Tue, 12 Jun 2018 23:57:55 +0800 Subject: [PATCH] resize query buffer more accurately 1. querybuf_peak has not been updated correctly in readQueryFromClient. 2. qbuf shrinking uses sdsalloc instead of sdsAllocSize see more details in issue #4983 --- src/networking.c | 4 +++- src/server.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/networking.c b/src/networking.c index 6ab16e293..805f3f0e9 100644 --- a/src/networking.c +++ b/src/networking.c @@ -2147,7 +2147,6 @@ void readQueryFromClient(connection *conn) { } qblen = sdslen(c->querybuf); - if (c->querybuf_peak < qblen) c->querybuf_peak = qblen; if (big_arg || sdsalloc(c->querybuf) < PROTO_IOBUF_LEN) { /* When reading a BIG_ARG we won't be reading more than that one arg * into the query buffer, so we don't need to pre-allocate more than we @@ -2187,6 +2186,9 @@ void readQueryFromClient(connection *conn) { } sdsIncrLen(c->querybuf,nread); + qblen = sdslen(c->querybuf); + if (c->querybuf_peak < qblen) c->querybuf_peak = qblen; + c->lastinteraction = server.unixtime; if (c->flags & CLIENT_MASTER) c->read_reploff += nread; atomicIncr(server.stat_net_input_bytes, nread); diff --git a/src/server.c b/src/server.c index dbc0a04e2..27a2f6c46 100644 --- a/src/server.c +++ b/src/server.c @@ -1664,7 +1664,7 @@ long long getInstantaneousMetric(int metric) { * * The function always returns 0 as it never terminates the client. */ int clientsCronResizeQueryBuffer(client *c) { - size_t querybuf_size = sdsAllocSize(c->querybuf); + size_t querybuf_size = sdsalloc(c->querybuf); time_t idletime = server.unixtime - c->lastinteraction; /* There are two conditions to resize the query buffer: