summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-07-19 13:49:00 +0200
committerantirez <antirez@gmail.com>2018-07-19 13:49:00 +0200
commitd4c5fc57db0c60780cbce8dfe2b6a5e457cedf83 (patch)
treeaef0987c6a2f01b85ec6870d35b429b49c408ed7
parent1c95c075966407729648fe676883a75be638824c (diff)
downloadredis-d4c5fc57db0c60780cbce8dfe2b6a5e457cedf83.tar.gz
clientsCronTrackExpansiveClients() skeleton and ideas.
-rw-r--r--src/server.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/server.c b/src/server.c
index 06826a356..53a8e5368 100644
--- a/src/server.c
+++ b/src/server.c
@@ -885,6 +885,28 @@ int clientsCronResizeQueryBuffer(client *c) {
return 0;
}
+/* This function is used in order to track clients using the biggest amount
+ * of memory in the latest few seconds. This way we can provide such information
+ * in the INFO output (clients section), without having to do an O(N) scan for
+ * all the clients.
+ *
+ * This is how it works. We have an array of CLIENTS_PEAK_MEM_USAGE_SLOTS slots
+ * where we track, for each, the biggest client output and input buffers we
+ * saw in that slot. Every slot correspond to one of the latest seconds, since
+ * the array is indexed by doing UNIXTIME % CLIENTS_PEAK_MEM_USAGE_SLOTS.
+ *
+ * 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
+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);
+ return 0; /* This function never terminates the client. */
+}
+
#define CLIENTS_CRON_MIN_ITERATIONS 5
void clientsCron(void) {
/* Make sure to process at least numclients/server.hz of clients
@@ -917,6 +939,7 @@ void clientsCron(void) {
* terminated. */
if (clientsCronHandleTimeout(c,now)) continue;
if (clientsCronResizeQueryBuffer(c)) continue;
+ if (clientsCronTrackExpansiveClients(c)) continue;
}
}