summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-03-23 19:15:02 +0100
committerantirez <antirez@gmail.com>2010-03-23 19:15:02 +0100
commit1763929f2379b8f4a5cb380987ff1cdb1f762f51 (patch)
tree0ddad46d5e97280965b57d208fcffb1d066abbab
parentcf87ebf22d0a75aada2486dea17117c1e8b7072b (diff)
downloadredis-1763929f2379b8f4a5cb380987ff1cdb1f762f51.tar.gz
the Cron timer function is now called 10 times per second instead of 1 time per second to make Redis more responsibe to BGSAVE and to delete expired keys more incrementally
-rw-r--r--redis.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/redis.c b/redis.c
index 3fb351825..6b16d8578 100644
--- a/redis.c
+++ b/redis.c
@@ -91,7 +91,7 @@
#define REDIS_CONFIGLINE_MAX 1024
#define REDIS_OBJFREELIST_MAX 1000000 /* Max number of objects to cache */
#define REDIS_MAX_SYNC_TIME 60 /* Slave can't take more to sync */
-#define REDIS_EXPIRELOOKUPS_PER_CRON 100 /* try to expire 100 keys/second */
+#define REDIS_EXPIRELOOKUPS_PER_CRON 10 /* try to expire 10 keys/loop */
#define REDIS_MAX_WRITE_PER_EVENT (1024*64)
#define REDIS_REQUEST_MAX_SIZE (1024*1024*256) /* max bytes in inline command */
@@ -1273,7 +1273,7 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
size = dictSlots(server.db[j].dict);
used = dictSize(server.db[j].dict);
vkeys = dictSize(server.db[j].expires);
- if (!(loops % 5) && (used || vkeys)) {
+ if (!(loops % 50) && (used || vkeys)) {
redisLog(REDIS_VERBOSE,"DB %d: %lld keys (%lld volatile) in %lld slots HT.",j,used,vkeys,size);
/* dictPrintStats(server.dict); */
}
@@ -1285,10 +1285,10 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
* if we resize the HT while there is the saving child at work actually
* a lot of memory movements in the parent will cause a lot of pages
* copied. */
- if (server.bgsavechildpid == -1) tryResizeHashTables();
+ if (server.bgsavechildpid == -1 && !(loops % 10)) tryResizeHashTables();
/* Show information about connected clients */
- if (!(loops % 5)) {
+ if (!(loops % 50)) {
redisLog(REDIS_VERBOSE,"%d clients connected (%d slaves), %zu bytes in use, %d shared objects",
listLength(server.clients)-listLength(server.slaves),
listLength(server.slaves),
@@ -1297,7 +1297,7 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
}
/* Close connections of timedout clients */
- if ((server.maxidletime && !(loops % 10)) || server.blpop_blocked_clients)
+ if ((server.maxidletime && !(loops % 100)) || server.blpop_blocked_clients)
closeTimedoutClients();
/* Check if a background saving or AOF rewrite in progress terminated */
@@ -1372,7 +1372,7 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
retval = (server.vm_max_threads == 0) ?
vmSwapOneObjectBlocking() :
vmSwapOneObjectThreaded();
- if (retval == REDIS_ERR && (loops % 30) == 0 &&
+ if (retval == REDIS_ERR && !(loops % 300) &&
zmalloc_used_memory() >
(server.vm_max_memory+server.vm_max_memory/10))
{
@@ -1387,13 +1387,13 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
}
/* Check if we should connect to a MASTER */
- if (server.replstate == REDIS_REPL_CONNECT) {
+ if (server.replstate == REDIS_REPL_CONNECT && !(loops % 10)) {
redisLog(REDIS_NOTICE,"Connecting to MASTER...");
if (syncWithMaster() == REDIS_OK) {
redisLog(REDIS_NOTICE,"MASTER <-> SLAVE sync succeeded");
}
}
- return 1000;
+ return 100;
}
/* This function gets called every time Redis is entering the