Skip to content

Commit

Permalink
Add a new option to set delay to restart a stopped worker
Browse files Browse the repository at this point in the history
This is still in POC stage.

This tries to solve the problem that restarting each worker is delayed
one by one, with as simple as possible.

However, this fix can't prevent the above problem...
  • Loading branch information
daipom committed May 25, 2022
1 parent 9f37af5 commit 6039a62
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/serverengine/multi_worker_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def reload_config

@start_worker_delay = @config[:start_worker_delay] || 0
@start_worker_delay_rand = @config[:start_worker_delay_rand] || 0.2
@restart_worker_delay = @config[:restart_worker_delay] || 0

scale_workers(@config[:workers] || 1)

Expand All @@ -97,6 +98,7 @@ def wait_tick

def keepalive_workers
num_alive = 0
is_restarting = false

@monitors.each_with_index do |m,wid|
if m && m.alive?
Expand All @@ -116,6 +118,10 @@ def keepalive_workers
elsif wid < @num_workers
# scale up or reboot
unless @stop
if m && @restart_worker_delay > 0 && !is_restarting
is_restarting = true
sleep @restart_worker_delay
end
@monitors[wid] = delayed_start_worker(wid)
num_alive += 1
end
Expand Down

0 comments on commit 6039a62

Please sign in to comment.