From ac083409429ea46f3bf83f325c78853f480e8ffb Mon Sep 17 00:00:00 2001 From: Binbin Date: Wed, 12 Mar 2025 12:35:00 +0800 Subject: [PATCH] Enable client eviction by default, set maxmemory-clients too 100% by default The client eviction introduced in 2753429c99425e3d0216cba79e0e61192975f252, at that time, the main idea of our introduction was to protect key data from being evicted, which is the server's perspective. In fact, the accumulated client output buffer can also violate the maxmemory contract and causing the machine to OOM. Signed-off-by: Binbin --- src/config.c | 2 +- tests/integration/replication-buffer.tcl | 1 + valkey.conf | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 312d47b948..a5225aaafa 100644 --- a/src/config.c +++ b/src/config.c @@ -3344,7 +3344,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, applyClientMaxMemoryUsage), + createSSizeTConfig("maxmemory-clients", NULL, MODIFIABLE_CONFIG, -100, SSIZE_MAX, server.maxmemory_clients, -100, 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 */ diff --git a/tests/integration/replication-buffer.tcl b/tests/integration/replication-buffer.tcl index 66a8581dcc..beaa25cda7 100644 --- a/tests/integration/replication-buffer.tcl +++ b/tests/integration/replication-buffer.tcl @@ -301,6 +301,7 @@ test "Replica client-output-buffer size is limited to backlog_limit/16 when no r set master [srv 0 client] set master_host [srv 0 host] set master_port [srv 0 port] + $master config set maxmemory-clients 0 $master config set maxmemory-policy allkeys-lru $master config set repl-backlog-size 16384 diff --git a/valkey.conf b/valkey.conf index df12b72d24..5891b40eab 100644 --- a/valkey.conf +++ b/valkey.conf @@ -2303,14 +2303,16 @@ client-output-buffer-limit pubsub 32mb 8mb 60 # client-query-buffer-limit 1gb # In some scenarios client connections can hog up memory leading to OOM -# errors or data eviction. To avoid this we can cap the accumulated memory +# errors or key eviction from the server perspective. And it may also violate +# maxmemory and causing the machine to OOM from the process perspective. +# +# To avoid or alleviate these problems we can cap the accumulated memory # used by all client connections (all pubsub and normal clients). Once we # reach that limit connections will be dropped by the server freeing up # memory. The server will attempt to drop the connections using the most # memory first. We call this mechanism "client eviction". # # Client eviction is configured using the maxmemory-clients setting as follows: -# 0 - client eviction is disabled (default) # # A memory value can be used for the client eviction threshold, # for example: @@ -2320,6 +2322,9 @@ client-output-buffer-limit pubsub 32mb 8mb 60 # is based on a percentage of the maxmemory setting. For example to set client # eviction at 5% of maxmemory: # maxmemory-clients 5% +# +# Client eviction is enabled by default and the value is 100% of maxmemory. +maxmemory-clients 100% # In the server protocol, bulk requests, that are, elements representing single # strings, are normally limited to 512 mb. However you can change this limit