diff options
author | antirez <antirez@gmail.com> | 2018-07-23 14:21:04 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-07-23 14:21:04 +0200 |
commit | b65ddfb16a7060a543b523feadeca1234cffd323 (patch) | |
tree | e4e28a774d0bc74559ea5013883758b87a13a09b | |
parent | e6ea603ad3ae53d4d33c48ec94699912dcfac716 (diff) | |
download | redis-b65ddfb16a7060a543b523feadeca1234cffd323.tar.gz |
Dynamic HZ: adapt cron frequency to number of clients.dynamic-hz
-rw-r--r-- | src/server.c | 11 | ||||
-rw-r--r-- | src/server.h | 11 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/server.c b/src/server.c index 557af84d9..aff7911e4 100644 --- a/src/server.c +++ b/src/server.c @@ -1096,6 +1096,17 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { /* Update the time cache. */ updateCachedTime(); + /* Adapt the server.hz value to the number of configured clients. If we have + * many clients, we want to call serverCron() with an higher frequency. */ + server.hz = server.config_hz; + while (listLength(server.clients) / server.hz > MAX_CLIENTS_PER_CLOCK_TICK) { + server.hz *= 2; + if (server.hz > CONFIG_MAX_HZ) { + server.hz = CONFIG_MAX_HZ; + break; + } + } + run_with_period(100) { trackInstantaneousMetric(STATS_METRIC_COMMAND,server.stat_numcommands); trackInstantaneousMetric(STATS_METRIC_NET_INPUT, diff --git a/src/server.h b/src/server.h index 4ac323da1..a139b5440 100644 --- a/src/server.h +++ b/src/server.h @@ -78,12 +78,13 @@ typedef long long mstime_t; /* millisecond time type. */ #define C_ERR -1 /* Static server configuration */ -#define CONFIG_DEFAULT_HZ 10 /* Time interrupt calls/sec. */ +#define CONFIG_DEFAULT_HZ 10 /* Time interrupt calls/sec. */ #define CONFIG_MIN_HZ 1 #define CONFIG_MAX_HZ 500 -#define CONFIG_DEFAULT_SERVER_PORT 6379 /* TCP port */ -#define CONFIG_DEFAULT_TCP_BACKLOG 511 /* TCP listen backlog */ -#define CONFIG_DEFAULT_CLIENT_TIMEOUT 0 /* default client timeout: infinite */ +#define MAX_CLIENTS_PER_CLOCK_TICK 200 /* HZ is adapted based on that. */ +#define CONFIG_DEFAULT_SERVER_PORT 6379 /* TCP port. */ +#define CONFIG_DEFAULT_TCP_BACKLOG 511 /* TCP listen backlog. */ +#define CONFIG_DEFAULT_CLIENT_TIMEOUT 0 /* Default client timeout: infinite */ #define CONFIG_DEFAULT_DBNUM 16 #define CONFIG_MAX_LINE 1024 #define CRON_DBS_PER_CALL 16 @@ -91,7 +92,7 @@ typedef long long mstime_t; /* millisecond time type. */ #define PROTO_SHARED_SELECT_CMDS 10 #define OBJ_SHARED_INTEGERS 10000 #define OBJ_SHARED_BULKHDR_LEN 32 -#define LOG_MAX_LEN 1024 /* Default maximum length of syslog messages */ +#define LOG_MAX_LEN 1024 /* Default maximum length of syslog messages.*/ #define AOF_REWRITE_PERC 100 #define AOF_REWRITE_MIN_SIZE (64*1024*1024) #define AOF_REWRITE_ITEMS_PER_CMD 64 |