summaryrefslogtreecommitdiffstats
path: root/database/engine/rrdengine.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-09-13 05:05:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-09-13 05:05:25 +0000
commitd72015c7962af72903326a01fb114f8f2d37eebc (patch)
tree5bb5ae6928f3f2a92f478f69c2f5c9aa9333fbf8 /database/engine/rrdengine.c
parentReleasing debian version 1.17.0-3. (diff)
downloadnetdata-d72015c7962af72903326a01fb114f8f2d37eebc.tar.xz
netdata-d72015c7962af72903326a01fb114f8f2d37eebc.zip
Merging upstream version 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: