From 62de066ee200e04df2376c6e14ee03dc85786d93 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Thu, 30 Jan 2020 11:57:20 +0300 Subject: [PATCH] Feature - cleanUpKeysAmount setting added. #2554 --- .../main/java/org/redisson/config/Config.java | 39 +++++++++++++++---- .../org/redisson/eviction/EvictionTask.java | 3 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/redisson/src/main/java/org/redisson/config/Config.java b/redisson/src/main/java/org/redisson/config/Config.java index 1edabd781..95c9c2316 100644 --- a/redisson/src/main/java/org/redisson/config/Config.java +++ b/redisson/src/main/java/org/redisson/config/Config.java @@ -84,7 +84,10 @@ public class Config { private boolean useScriptCache = false; private int minCleanUpDelay = 5; + private int maxCleanUpDelay = 30*60; + + private int cleanUpKeysAmount = 100; /** * AddressResolverGroupFactory switch between default and round robin @@ -104,6 +107,7 @@ public class Config { setMinCleanUpDelay(oldConf.getMinCleanUpDelay()); setMaxCleanUpDelay(oldConf.getMaxCleanUpDelay()); + setCleanUpKeysAmount(oldConf.getCleanUpKeysAmount()); setDecodeInExecutor(oldConf.isDecodeInExecutor()); setUseScriptCache(oldConf.isUseScriptCache()); setKeepPubSubOrder(oldConf.isKeepPubSubOrder()); @@ -702,9 +706,11 @@ public class Config { } /** - * Defines minimal delay of clean up process for expired entries. + * Defines minimum delay in seconds for clean up process of expired entries. + *

+ * Applied to JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects. *

- * Used in JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects + * Default is 5. * * @param minCleanUpDelay - delay in seconds * @return config @@ -719,10 +725,12 @@ public class Config { } /** - * Defines maximal delay of clean up process for expired entries. + * Defines maximum delay in seconds for clean up process of expired entries. *

- * Used in JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects - * + * Applied to JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects. + *

+ * Default is 1800. + * * @param maxCleanUpDelay - delay in seconds * @return config */ @@ -731,6 +739,23 @@ public class Config { return this; } - - + public int getCleanUpKeysAmount() { + return cleanUpKeysAmount; + } + + /** + * Defines expired keys amount deleted per single operation during clean up process of expired entries. + *

+ * Applied to JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects. + *

+ * Default is 100. + * + * @param cleanUpKeysAmount - delay in seconds + * @return config + */ + public Config setCleanUpKeysAmount(int cleanUpKeysAmount) { + this.cleanUpKeysAmount = cleanUpKeysAmount; + return this; + } + } diff --git a/redisson/src/main/java/org/redisson/eviction/EvictionTask.java b/redisson/src/main/java/org/redisson/eviction/EvictionTask.java index 9e7ef15ae..2274d5c03 100644 --- a/redisson/src/main/java/org/redisson/eviction/EvictionTask.java +++ b/redisson/src/main/java/org/redisson/eviction/EvictionTask.java @@ -36,7 +36,7 @@ abstract class EvictionTask implements Runnable { final Deque sizeHistory = new LinkedList(); final int minDelay; final int maxDelay; - final int keysLimit = 100; + final int keysLimit; int delay = 5; @@ -47,6 +47,7 @@ abstract class EvictionTask implements Runnable { this.executor = executor; this.minDelay = executor.getConnectionManager().getCfg().getMinCleanUpDelay(); this.maxDelay = executor.getConnectionManager().getCfg().getMaxCleanUpDelay(); + this.keysLimit = executor.getConnectionManager().getCfg().getCleanUpKeysAmount(); } public void schedule() {