From 8f5d8f3de6cae180af37917ef978a4affc2cd464 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 13 Sep 2019 07:05:16 +0200 Subject: Adding upstream version 1.17.1. Signed-off-by: Daniel Baumann --- database/engine/rrdengine.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'database/engine/rrdengine.c') diff --git a/database/engine/rrdengine.c b/database/engine/rrdengine.c index 39d148578..36d917541 100644 --- a/database/engine/rrdengine.c +++ b/database/engine/rrdengine.c @@ -676,7 +676,7 @@ void timer_cb(uv_timer_t* handle) /* Flushes dirty pages when timer expires */ #define TIMER_PERIOD_MS (1000) -#define CMD_BATCH_SIZE (256) +#define MAX_CMD_BATCH_SIZE (256) void rrdeng_worker(void* arg) { @@ -687,6 +687,7 @@ void rrdeng_worker(void* arg) enum rrdeng_opcode opcode; uv_timer_t timer_req; struct rrdeng_cmd cmd; + unsigned cmd_batch_size; rrdeng_init_cmd_queue(wc); @@ -723,10 +724,20 @@ void rrdeng_worker(void* arg) shutdown = 0; while (shutdown == 0 || uv_loop_alive(loop)) { uv_run(loop, UV_RUN_DEFAULT); + /* wait for commands */ + cmd_batch_size = 0; do { + /* + * Avoid starving the loop when there are too many commands coming in. + * timer_cb will interrupt the loop again to allow serving more commands. + */ + if (unlikely(cmd_batch_size >= MAX_CMD_BATCH_SIZE)) + break; + cmd = rrdeng_deq_cmd(wc); opcode = cmd.opcode; + ++cmd_batch_size; switch (opcode) { case RRDENG_NOOP: -- cgit v1.2.3