Dynamic HZ: adapt cron frequency to number of clients.

This commit is contained in:
antirez 2018-07-23 14:21:04 +02:00
parent 6bfbad38af
commit 3d32af7ec6
2 changed files with 17 additions and 5 deletions

View File

@ -1096,6 +1096,17 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
/* Update the time cache. */ /* Update the time cache. */
updateCachedTime(); 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) { run_with_period(100) {
trackInstantaneousMetric(STATS_METRIC_COMMAND,server.stat_numcommands); trackInstantaneousMetric(STATS_METRIC_COMMAND,server.stat_numcommands);
trackInstantaneousMetric(STATS_METRIC_NET_INPUT, trackInstantaneousMetric(STATS_METRIC_NET_INPUT,

View File

@ -78,12 +78,13 @@ typedef long long mstime_t; /* millisecond time type. */
#define C_ERR -1 #define C_ERR -1
/* Static server configuration */ /* 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_MIN_HZ 1
#define CONFIG_MAX_HZ 500 #define CONFIG_MAX_HZ 500
#define CONFIG_DEFAULT_SERVER_PORT 6379 /* TCP port */ #define MAX_CLIENTS_PER_CLOCK_TICK 200 /* HZ is adapted based on that. */
#define CONFIG_DEFAULT_TCP_BACKLOG 511 /* TCP listen backlog */ #define CONFIG_DEFAULT_SERVER_PORT 6379 /* TCP port. */
#define CONFIG_DEFAULT_CLIENT_TIMEOUT 0 /* default client timeout: infinite */ #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_DEFAULT_DBNUM 16
#define CONFIG_MAX_LINE 1024 #define CONFIG_MAX_LINE 1024
#define CRON_DBS_PER_CALL 16 #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 PROTO_SHARED_SELECT_CMDS 10
#define OBJ_SHARED_INTEGERS 10000 #define OBJ_SHARED_INTEGERS 10000
#define OBJ_SHARED_BULKHDR_LEN 32 #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_PERC 100
#define AOF_REWRITE_MIN_SIZE (64*1024*1024) #define AOF_REWRITE_MIN_SIZE (64*1024*1024)
#define AOF_REWRITE_ITEMS_PER_CMD 64 #define AOF_REWRITE_ITEMS_PER_CMD 64