summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-07-19 13:54:15 +0200
committerantirez <antirez@gmail.com>2018-07-19 13:54:20 +0200
commit85a1b4f807fd7651184363fadb4a8cdac864adc6 (patch)
treec39b5e29ab2e5329a3900ca11630802d2c99fecd
parentd4c5fc57db0c60780cbce8dfe2b6a5e457cedf83 (diff)
downloadredis-85a1b4f807fd7651184363fadb4a8cdac864adc6.tar.gz
clientsCronTrackExpansiveClients() actual implementation.
-rw-r--r--src/server.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/server.c b/src/server.c
index 53a8e5368..b14d0740e 100644
--- a/src/server.c
+++ b/src/server.c
@@ -897,13 +897,26 @@ int clientsCronResizeQueryBuffer(client *c) {
*
* When we want to know what was recently the peak memory usage, we just scan
* such few slots searching for the maximum value. */
-#define CLIENTS_PEAK_MEM_USAGE_SLOTS 10
+#define CLIENTS_PEAK_MEM_USAGE_SLOTS 8
size_t ClientsPeakMemInput[CLIENTS_PEAK_MEM_USAGE_SLOTS];
size_t ClientsPeakMemOutput[CLIENTS_PEAK_MEM_USAGE_SLOTS];
int clientsCronTrackExpansiveClients(client *c) {
size_t in_usage = sdsAllocSize(c->querybuf);
size_t out_usage = getClientOutputBufferMemoryUsage(c);
+ int i = server.unixtime % CLIENTS_PEAK_MEM_USAGE_SLOTS;
+ int j = (i+1) % CLIENTS_PEAK_MEM_USAGE_SLOTS;
+
+ /* Always zero the next sample, so that when we switch to that second, we'll
+ * only register samples that are greater in that second without considering
+ * the history of such slot. */
+ ClientsPeakMemInput[j] = 0;
+ ClientsPeakMemOutput[j] = 0;
+
+ /* Track the biggest values observed so far in this slot. */
+ if (in_usage > ClientsPeakMemInput[i]) ClientsPeakMemInput[i] = in_usage;
+ if (out_usage > ClientsPeakMemOutput[i]) ClientsPeakMemOutput[i] = out_usage;
+
return 0; /* This function never terminates the client. */
}