delayed_job
delayed_job copied to clipboard
Question: Why not parallelize worker start|stop|restart
I wonder why daemonize is not parallelized (via Thread). It would at least stop worker much faster. Thanks for your opinion.
Regards, Phil
For what it's worth, I've been doing this via an awful hack:
#!/usr/bin/env ruby
# frozen_string_literal: true
require File.expand_path(File.join(File.dirname(__FILE__), "..", "config", "environment"))
require "delayed/command"
module DJParallelStartAndStop
# By default, DJ stops its worker processes one at a time, which can take
# a long time given a big pool or with busy queues.
# Move the Daemons calls into their own threads, so we can ask all our
# workers to start/stop in parallel.
def daemonize
@process_threads = []
# run_process calls before_fork, which isn't thread safe (it non-atomically sets @files_to_reopen).
# Call it once on the main thread here to try & avoid race conditions.
Delayed::Worker.before_fork
super
@process_threads.each(&:join)
end
def run_process(process_name, options = {})
@process_threads << Thread.new {
super
}
end
end
Delayed::Command.prepend(DJParallelStartAndStop)
Delayed::Command.new(ARGV).daemonize
which has cut our restart times on a 8-pool worker from 45 seconds to 10.
Closing stale