From d0c64d78d46a56cc3c83f4681f6bd0a451634208 Mon Sep 17 00:00:00 2001 From: Moti Cohen Date: Thu, 25 Jul 2024 13:22:02 +0300 Subject: [PATCH] On active expire, factor maxToExpire based on Hertz (#13439) --- src/expire.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/expire.c b/src/expire.c index 646f752a9..d4289d758 100644 --- a/src/expire.c +++ b/src/expire.c @@ -94,7 +94,8 @@ int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) { #define ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC 25 /* Max % of CPU to use. */ #define ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE 10 /* % of stale keys after which we do extra efforts. */ -#define HFE_ACTIVE_EXPIRE_CYCLE_FIELDS 1000 + +#define HFE_DB_BASE_ACTIVE_EXPIRE_FIELDS_PER_SEC 10000 /* Data used by the expire dict scan callback. */ typedef struct { @@ -151,8 +152,6 @@ static inline void activeExpireHashFieldCycle(int type) { static uint64_t activeExpirySequence = 0; /* Threshold for adjusting maxToExpire */ const uint32_t EXPIRED_FIELDS_TH = 1000000; - /* Maximum number of fields to actively expire in a single call */ - uint32_t maxToExpire = HFE_ACTIVE_EXPIRE_CYCLE_FIELDS; redisDb *db = server.db + currentDb; @@ -163,6 +162,9 @@ static inline void activeExpireHashFieldCycle(int type) { return; } + /* Maximum number of fields to actively expire on a single call */ + uint32_t maxToExpire = HFE_DB_BASE_ACTIVE_EXPIRE_FIELDS_PER_SEC / server.hz; + /* If running for a while and didn't manage to active-expire all expired fields of * currentDb (i.e. activeExpirySequence becomes significant) then adjust maxToExpire */ if ((activeExpirySequence > EXPIRED_FIELDS_TH) && (type == ACTIVE_EXPIRE_CYCLE_SLOW)) {