summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-08-05 16:11:56 +0200
committerantirez <antirez@gmail.com>2013-08-05 16:14:28 +0200
commit66a26471dc829bb60641781cbf8e74f40d2b7bb0 (patch)
tree17285c2a5e68c8e3c9b16180be203b391ab39e33
parentb09ea1bd90c96ad26f0eb109ffcd36e2e7cb21e1 (diff)
downloadredis-66a26471dc829bb60641781cbf8e74f40d2b7bb0.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 52f9b1f26..31456f00a 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -697,6 +697,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
@@ -707,6 +708,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];
@@ -714,7 +716,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) {
@@ -751,7 +763,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;