Commit e64d0890 authored by antirez's avatar antirez
Browse files

Less gettimeofday() calls in activeExpireCycle().

mstime() is not going to change significantly every 16 iterations, so
now we update `now` with the current milliseconds time only when we
check if the time limit was reached.
parent db5cdb17
...@@ -766,6 +766,7 @@ void activeExpireCycle(int type) { ...@@ -766,6 +766,7 @@ void activeExpireCycle(int type) {
int j, iteration = 0; int j, iteration = 0;
int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL; int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL;
long long start = ustime(), timelimit; long long start = ustime(), timelimit;
long long now = start/1000;
if (type == ACTIVE_EXPIRE_CYCLE_FAST) { if (type == ACTIVE_EXPIRE_CYCLE_FAST) {
/* Don't start a fast cycle if the previous cycle did not exited /* Don't start a fast cycle if the previous cycle did not exited
...@@ -810,7 +811,7 @@ void activeExpireCycle(int type) { ...@@ -810,7 +811,7 @@ void activeExpireCycle(int type) {
* of the keys were expired. */ * of the keys were expired. */
do { do {
unsigned long num, slots; unsigned long num, slots;
long long now, ttl_sum; long long ttl_sum;
int ttl_samples; int ttl_samples;
/* If there is nothing to expire try next DB ASAP. */ /* If there is nothing to expire try next DB ASAP. */
...@@ -819,7 +820,6 @@ void activeExpireCycle(int type) { ...@@ -819,7 +820,6 @@ void activeExpireCycle(int type) {
break; break;
} }
slots = dictSlots(db->expires); slots = dictSlots(db->expires);
now = mstime();
/* When there are less than 1% filled slots getting random /* When there are less than 1% filled slots getting random
* keys is expensive, so stop here waiting for better times... * keys is expensive, so stop here waiting for better times...
...@@ -862,7 +862,9 @@ void activeExpireCycle(int type) { ...@@ -862,7 +862,9 @@ void activeExpireCycle(int type) {
* caller waiting for the other active expire cycle. */ * caller waiting for the other active expire cycle. */
iteration++; iteration++;
if ((iteration & 0xf) == 0) { /* check once every 16 iterations. */ if ((iteration & 0xf) == 0) { /* check once every 16 iterations. */
long long elapsed = ustime()-start; now = ustime();
long long elapsed = now-start;
now /= 1000; /* We need now in milliseconds within the loop. */
latencyAddSampleIfNeeded("expire-cycle",elapsed/1000); latencyAddSampleIfNeeded("expire-cycle",elapsed/1000);
if (elapsed > timelimit) timelimit_exit = 1; if (elapsed > timelimit) timelimit_exit = 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment