summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-04-30 10:04:21 +0200
committerantirez <antirez@gmail.com>2015-04-30 10:04:21 +0200
commit0b4ab6361edf8544ee0c3656966b453686b12610 (patch)
treeb98146ef3d2e0640c4e0e929ef3a9c981954cb1b
parent0b605e54ff9c59e96fa4f275a7e3ab2e0c09e609 (diff)
downloadredis-0b4ab6361edf8544ee0c3656966b453686b12610.tar.gz
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.
-rw-r--r--src/redis.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/redis.c b/src/redis.c
index 6070175ac..c49d5b4d2 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -710,6 +710,7 @@ void activeExpireCycle(int type) {
int j, iteration = 0;
int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL;
long long start = ustime(), timelimit;
+ long long now = start/1000;
if (type == ACTIVE_EXPIRE_CYCLE_FAST) {
/* Don't start a fast cycle if the previous cycle did not exited
@@ -754,7 +755,7 @@ void activeExpireCycle(int type) {
* of the keys were expired. */
do {
unsigned long num, slots;
- long long now, ttl_sum;
+ long long ttl_sum;
int ttl_samples;
/* If there is nothing to expire try next DB ASAP. */
@@ -763,7 +764,6 @@ void activeExpireCycle(int type) {
break;
}
slots = dictSlots(db->expires);
- now = mstime();
/* When there are less than 1% filled slots getting random
* keys is expensive, so stop here waiting for better times...
@@ -806,7 +806,9 @@ void activeExpireCycle(int type) {
* caller waiting for the other active expire cycle. */
iteration++;
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);
if (elapsed > timelimit) timelimit_exit = 1;