summaryrefslogtreecommitdiffstats
path: root/database/engine/rrdengine.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-09-13 05:05:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-09-13 05:05:16 +0000
commit8f5d8f3de6cae180af37917ef978a4affc2cd464 (patch)
tree4bfe1abc6d19c2dd635d1b83cc0e73d0aa6904ac /database/engine/rrdengine.c
parentAdding upstream version 1.17.0. (diff)
downloadnetdata-8f5d8f3de6cae180af37917ef978a4affc2cd464.tar.xz
netdata-8f5d8f3de6cae180af37917ef978a4affc2cd464.zip
Adding upstream version 1.17.1.upstream/1.17.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'database/engine/rrdengine.c')
-rw-r--r--database/engine/rrdengine.c13
1 files changed, 12 insertions, 1 deletions
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: