summaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-07-23 14:21:04 +0200
committerantirez <antirez@gmail.com>2018-07-23 14:21:04 +0200
commitb65ddfb16a7060a543b523feadeca1234cffd323 (patch)
treee4e28a774d0bc74559ea5013883758b87a13a09b /src/server.c
parente6ea603ad3ae53d4d33c48ec94699912dcfac716 (diff)
downloadredis-dynamic-hz.tar.gz
Dynamic HZ: adapt cron frequency to number of clients.dynamic-hz
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c11
1 files changed, 11 insertions, 0 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,