Skip to content

Commit

Permalink
add iteration and full scan delays to a task
Browse files Browse the repository at this point in the history
Added the ability to set iteration and full scan delays for a task.

iteration delay - max sleep time between iterations (in seconds).
full scan delay - sleep time between full scans (in seconds).

Related to #38
  • Loading branch information
zloidemon authored and LeonidVas committed Dec 4, 2020
1 parent da75bd6 commit e20a89d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ opt
* `args` - passed to `is_tuple_expired()` and `process_expired_tuple()` as additional context
* `tuples_per_iteration` - number of tuples will be checked by one iteration
* `full_scan_time` - time required for full index scan (in seconds)
* `iteration_delay` - max sleep time between iterations (in seconds)
* `full_scan_delay` - sleep time between full scans (in seconds)
* `force` - run, even on replica

### `expirationd.kill (name)`
Expand Down
24 changes: 21 additions & 3 deletions expirationd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ end

local function suspend_basic(scan_space, task, len)
local delay = (task.tuples_per_iteration * task.full_scan_time)
delay = math.min(delay / len, constants.max_delay)
delay = math.min(delay / len, task.iteration_delay)
fiber.sleep(delay)
end

Expand Down Expand Up @@ -163,8 +163,8 @@ local function worker_loop(task)
task.do_worker_iteration(task)
end

-- iteration is complete, yield
fiber.sleep(constants.max_delay)
-- Full scan iteration is complete, yield
fiber.sleep(task.full_scan_delay)
end
end

Expand Down Expand Up @@ -247,6 +247,8 @@ local function create_task(name)
is_tuple_expired = nil,
process_expired_tuple = nil,
args = nil,
iteration_delay = constants.max_delay,
full_scan_delay = constants.max_delay,
tuples_per_iteration = constants.default_tuples_per_iteration,
full_scan_time = constants.default_full_scan_time,
vinyl_assumed_space_len = constants.default_vinyl_assumed_space_len,
Expand Down Expand Up @@ -293,6 +295,8 @@ end
-- process_expired_tuple() as additional context
-- * tuples_per_iteration -- number of tuples will be checked by one iteration
-- * full_scan_time -- time required for full index scan (in seconds)
-- * iteration_delay -- max sleep time between iterations (in seconds)
-- * full_scan_delay -- sleep time between full scans (in seconds)
-- * force -- run task even on replica
-- }
local function expirationd_run_task(name, space_id, is_tuple_expired, options)
Expand Down Expand Up @@ -380,6 +384,20 @@ local function expirationd_run_task(name, space_id, is_tuple_expired, options)
task.do_worker_iteration = default_do_worker_iteration
end

if options.iteration_delay ~= nil then
if type(options.iteration_delay) ~= 'number' then
error("invalid type of iteration_delay value")
end
task.iteration_delay = options.iteration_delay
end

if options.full_scan_delay ~= nil then
if type(options.full_scan_delay) ~= 'number' then
error("invalid type of full_scan_delay value")
end
task.full_scan_delay = options.full_scan_delay
end

-- put the task to table
task_list[name] = task
-- run
Expand Down

0 comments on commit e20a89d

Please # to comment.