a simple prefork server framework / ruby port of perl's Parallel::Prefork
OTHER License
a simple prefork server framework. ruby port of perl's Parallel::Prefork PreforkEngine supports graceful shutdown and runtime reconfiguration
Add this line to your application's Gemfile:
gem 'prefork_engine'
And then execute:
$ bundle
Or install it yourself as:
$ gem install prefork_engine
pm = PreforkEngine.new(
"max_workers" => 3
"spawn_interval" => 1,
"err_respawn_interval" => 3,
"trap_signals" => {
"TERM" => "TERM",
"HUP" => "TERM"
}
)
while !pm.signal_received.match(/^(TERM|HUP)$/)
pm.start {
... do some work within the child process ...
}
end
pm.wait_all_children
create instance. accepts following attributes
number of worker processes (default: 10)
nterval in seconds between spawning child processes unless a child process exits abnormally (default: 0)
number of seconds to deter spawning of child processes after a worker exits abnormally (default: 1)
Hash of signals to be trapped. Manager process will trap the signals listed in the keys of the hash, and send the signal specified in the associated value (if any) to all worker processes. If the associated value is a String then it is treated as the name of the signal to be sent immediately to all the worker processes. If the value is an Array the first value is treated the name of the signal and the second value is treated as the interval (in seconds) between sending the signal to each worker process.
Proc object that is called when a child is reaped. Receives the instance to the current PreforkEngine, the child's pid, and its exit status.
Proc object that are called in the manager process before and after fork, if being set
The main routine. this method requires Proc object.
start
forks child processes and executes given Proc object within the child processes.
The start function returns true within manager process upon receiving a signal specified in the trap_signals
Sends singal to all worker processes
waits until all workers exit
https://metacpan.org/pod/Parallel::Prefork
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)