summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-08-05 16:11:56 +0200
committerantirez <antirez@gmail.com>2013-08-07 11:37:26 +0200
commitd9a4fd0f3224411dac217e8b879fcf1bf47b42e9 (patch)
tree897dd7666a171be02569e108d3cece387c47655c
parentab782615cc8094d413063c9bb02c2d4e412486c0 (diff)
downloadredis-d9a4fd0f3224411dac217e8b879fcf1bf47b42e9.tar.gz
Darft #2 for key collection algo: more improvements.
This commit makes the fast collection cycle time configurable, at the same time it does not allow to run a new fast collection cycle for the same amount of time as the max duration of the fast collection cycle.
-rw-r--r--src/redis.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/redis.c b/src/redis.c
index 1715f0984..621388824 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -654,6 +654,7 @@ int activeExpireCycleTryExpire(redisDb *db, struct dictEntry *de, long long now)
* more incrementally from the beforeSleep() function of the event loop. */
#define EXPIRED_HISTORY_LEN 10
+#define EXPIRE_FAST_CYCLE_DURATION 1000
void activeExpireCycle(int fast) {
/* This function has some global state in order to continue the work
@@ -664,6 +665,7 @@ void activeExpireCycle(int fast) {
unsigned int j, iteration = 0;
unsigned int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL;
long long start = ustime(), timelimit;
+ static long long last_fast_cycle = 0;
#if 0
static int expired_history[EXPIRED_HISTORY_LEN];
@@ -671,7 +673,17 @@ void activeExpireCycle(int fast) {
static int expired_perc_avg = 0;
#endif
- if (fast && !timelimit_exit) return;
+ if (fast) {
+ /* Don't start a fast cycle if the previous cycle did not exited
+ * for time limt. Also don't repeat a fast cycle for the same period
+ * as the fast cycle total duration itself. */
+ if (!timelimit_exit) return;
+ if (start < last_fast_cycle + EXPIRE_FAST_CYCLE_DURATION) {
+ printf("CANT START A FAST CYCLE\n");
+ return;
+ }
+ last_fast_cycle = start;
+ }
#if 0
if (fast) {
@@ -708,7 +720,7 @@ void activeExpireCycle(int fast) {
timelimit_exit = 0;
if (timelimit <= 0) timelimit = 1;
- if (fast) timelimit = 1000; /* 1 millisecond. */
+ if (fast) timelimit = EXPIRE_FAST_CYCLE_DURATION; /* in microseconds. */
for (j = 0; j < dbs_per_call; j++) {
int expired;