summaryrefslogtreecommitdiff
path: root/src/server.h
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/server.h
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/server.h')
-rw-r--r--src/server.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/server.h b/src/server.h
index 1ce5ff781..7e383c59b 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1197,7 +1197,7 @@ typedef struct client {
rax *client_tracking_prefixes; /* A dictionary of prefixes we are already
subscribed to in BCAST mode, in the
context of client side caching. */
- /* In updateClientMemUsage() we track the memory usage of
+ /* In updateClientMemoryUsage() we track the memory usage of
* each client and add it to the sum of all the clients of a given type,
* however we need to remember what was the old contribution of each
* client, and in which category the client was, in order to remove it
@@ -1551,7 +1551,7 @@ struct redisServer {
client *current_client; /* Current client executing the command. */
/* Stuff for client mem eviction */
- clientMemUsageBucket client_mem_usage_buckets[CLIENT_MEM_USAGE_BUCKETS];
+ clientMemUsageBucket* client_mem_usage_buckets;
rax *clients_timeout_table; /* Radix tree for blocked clients timeouts. */
int in_nested_call; /* If > 0, in a nested call of a call */
@@ -2577,8 +2577,8 @@ int handleClientsWithPendingReadsUsingThreads(void);
int stopThreadedIOIfNeeded(void);
int clientHasPendingReplies(client *c);
int islocalClient(client *c);
-int updateClientMemUsage(client *c);
-void updateClientMemUsageBucket(client *c);
+int updateClientMemUsageAndBucket(client *c);
+void removeClientFromMemUsageBucket(client *c, int allow_eviction);
void unlinkClient(client *c);
int writeToClient(client *c, int handler_installed);
void linkClient(client *c);
@@ -3117,6 +3117,8 @@ void initConfigValues();
void removeConfig(sds name);
sds getConfigDebugInfo();
int allowProtectedAction(int config, client *c);
+void initServerClientMemUsageBuckets();
+void freeServerClientMemUsageBuckets();
/* Module Configuration */
typedef struct ModuleConfig ModuleConfig;