From df94d6d13ba032af97cdbff93f59f0a554ca193c Mon Sep 17 00:00:00 2001 From: Ilya Grishnov Date: Tue, 27 Sep 2022 11:00:04 +0300 Subject: [PATCH] abstract: reduced increased CPU consumption Due to the fact that queue_state_fiber called box.ctrl.wait_r* every millisecond, the idle queue consumed more than 10% of CPU. The proposed solution makes calls to box.ctrl.wait_r* blocking until the read/write mode is changed. As a result, in idle mode, the queue_state_faber is in the suspended state, while the main fiber (for example, interactive in interactive-mode) is in the running state. Thus, CPU consumption is reduced to about ~1%. More detailed measurements are described in [1]. 1. https://github.com/tarantool/queue/pull/192 Closes #183 --- queue/abstract/queue_state.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/queue/abstract/queue_state.lua b/queue/abstract/queue_state.lua index 6583008a..9de20c9b 100644 --- a/queue/abstract/queue_state.lua +++ b/queue/abstract/queue_state.lua @@ -65,7 +65,7 @@ local function create_state_fiber(on_state_change_cb) fiber.self():name('queue_state_fiber') while true do if current == queue_state.states.WAITING then - local rc = pcall(box.ctl.wait_rw, 0.001) + local rc = pcall(box.ctl.wait_rw) if rc then current = queue_state.states.STARTUP log.info('Queue state changed: STARTUP') @@ -76,7 +76,7 @@ local function create_state_fiber(on_state_change_cb) log.info('Queue state changed: RUNNING') end elseif current == queue_state.states.RUNNING then - local rc = pcall(box.ctl.wait_ro, 0.001) + local rc = pcall(box.ctl.wait_ro) if rc then current = queue_state.states.ENDING on_state_change_cb(current)