summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorHarkrishn Patro <harkrisp@amazon.com>2022-12-06 22:26:56 -0800
committerGitHub <noreply@github.com>2022-12-07 08:26:56 +0200
commitc0267b3fa5808df475dec83c956b9a2bec112b90 (patch)
treefd3913a9b0d1fe8cbb08a0618ea719db886a9eb7 /src/config.c
parent8a315fc285fc54c678b97107a02ee1627f2c1ebf (diff)
downloadredis-c0267b3fa5808df475dec83c956b9a2bec112b90.tar.gz
Optimize client memory usage tracking operation while client eviction is disabled (#11348)
## Issue During the client input/output buffer processing, the memory usage is incrementally updated to keep track of clients going beyond a certain threshold `maxmemory-clients` to be evicted. However, this additional tracking activity leads to unnecessary CPU cycles wasted when no client-eviction is required. It is applicable in two cases. * `maxmemory-clients` is set to `0` which equates to no client eviction (applicable to all clients) * `CLIENT NO-EVICT` flag is set to `ON` which equates to a particular client not applicable for eviction. ## Solution * Disable client memory usage tracking during the read/write flow when `maxmemory-clients` is set to `0` or `client no-evict` is `on`. The memory usage is tracked only during the `clientCron` i.e. it gets periodically updated. * Cleanup the clients from the memory usage bucket when client eviction is disabled. * When the maxmemory-clients config is enabled or disabled at runtime, we immediately update the memory usage buckets for all clients (tested scanning 80000 took some 20ms) Benchmark shown that this can improve performance by about 5% in certain situations. Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c
index e57946429..78553b758 100644
--- a/src/config.c
+++ b/src/config.c
@@ -2976,6 +2976,37 @@ void rewriteConfigLatencyTrackingInfoPercentilesOutputOption(standardConfig *con
rewriteConfigRewriteLine(state,name,line,1);
}
+static int applyClientMaxMemoryUsage(const char **err) {
+ UNUSED(err);
+ listIter li;
+ listNode *ln;
+
+ /* server.client_mem_usage_buckets is an indication that the previous config
+ * was non-zero, in which case we can exit and no apply is needed. */
+ if(server.maxmemory_clients !=0 && server.client_mem_usage_buckets)
+ return 1;
+ if (server.maxmemory_clients != 0)
+ initServerClientMemUsageBuckets();
+
+ /* When client eviction is enabled update memory buckets for all clients.
+ * When disabled, clear that data structure. */
+ listRewind(server.clients, &li);
+ while ((ln = listNext(&li)) != NULL) {
+ client *c = listNodeValue(ln);
+ if (server.maxmemory_clients == 0) {
+ /* Remove client from memory usage bucket. */
+ removeClientFromMemUsageBucket(c, 0);
+ } else {
+ /* Update each client(s) memory usage and add to appropriate bucket. */
+ updateClientMemUsageAndBucket(c);
+ }
+ }
+
+ if (server.maxmemory_clients == 0)
+ freeServerClientMemUsageBuckets();
+ return 1;
+}
+
standardConfig static_configs[] = {
/* Bool configs */
createBoolConfig("rdbchecksum", NULL, IMMUTABLE_CONFIG, server.rdb_checksum, 1, NULL, NULL),
@@ -3146,7 +3177,7 @@ standardConfig static_configs[] = {
createSizeTConfig("hll-sparse-max-bytes", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.hll_sparse_max_bytes, 3000, MEMORY_CONFIG, NULL, NULL),
createSizeTConfig("tracking-table-max-keys", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.tracking_table_max_keys, 1000000, INTEGER_CONFIG, NULL, NULL), /* Default: 1 million keys max. */
createSizeTConfig("client-query-buffer-limit", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, 1024*1024, LONG_MAX, server.client_max_querybuf_len, 1024*1024*1024, MEMORY_CONFIG, NULL, NULL), /* Default: 1GB max query buffer. */
- createSSizeTConfig("maxmemory-clients", NULL, MODIFIABLE_CONFIG, -100, SSIZE_MAX, server.maxmemory_clients, 0, MEMORY_CONFIG | PERCENT_CONFIG, NULL, NULL),
+ createSSizeTConfig("maxmemory-clients", NULL, MODIFIABLE_CONFIG, -100, SSIZE_MAX, server.maxmemory_clients, 0, MEMORY_CONFIG | PERCENT_CONFIG, NULL, applyClientMaxMemoryUsage),
/* Other configs */
createTimeTConfig("repl-backlog-ttl", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.repl_backlog_time_limit, 60*60, INTEGER_CONFIG, NULL, NULL), /* Default: 1 hour */