Class: ParallelServer::Prefork
- Inherits:
-
Object
- Object
- ParallelServer::Prefork
- Defined in:
- lib/parallel_server/prefork.rb
Defined Under Namespace
Classes: Child, Conversation
Constant Summary collapse
- DEFAULT_MIN_PROCESSES =
5- DEFAULT_MAX_PROCESSES =
20- DEFAULT_MAX_THREADS =
1- DEFAULT_STANDBY_THREADS =
5- DEFAULT_MAX_IDLE =
10- DEFAULT_MAX_USE =
1000- DEFAULT_WATCHDOG_TIMER =
600- DEFAULT_WATCHDOG_SIGNAL =
'TERM'
Instance Attribute Summary collapse
-
#child_status ⇒ Object
readonly
Returns the value of attribute child_status.
Instance Method Summary collapse
- #detach_children ⇒ void
-
#initialize(*args) ⇒ Prefork
constructor
A new instance of Prefork.
- #reload(*args) ⇒ void
- #start {|sock, addr, child| ... } ⇒ void
- #stop ⇒ void
- #stop! ⇒ void
Constructor Details
#initialize(host = nil, port, opts = {}) ⇒ Prefork #initialize(socket, opts = {}) ⇒ Prefork #initialize(sockets, opts = {}) ⇒ Prefork
Returns a new instance of Prefork.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/parallel_server/prefork.rb', line 44 def initialize(*args) @sockets, @host, @port, @opts = parse_args(*args) set_variables_from_opts @from_child = {} # IO(r) => pid @to_child = {} # IO(r) => IO(w) @child_status = {} # IO(r) => Hash @children = [] # pid @loop = true @sockets_created = false end |
Instance Attribute Details
#child_status ⇒ Object (readonly)
Returns the value of attribute child_status.
16 17 18 |
# File 'lib/parallel_server/prefork.rb', line 16 def child_status @child_status end |
Instance Method Details
#detach_children ⇒ void
107 108 109 110 111 112 113 |
# File 'lib/parallel_server/prefork.rb', line 107 def detach_children t = Time.now + 5 talk_to_children(detach: true) while Time.now < t && @child_status.values.any?{|s| s[:status] == :run} watch_children end end |
#reload(host = nil, port, opts = {}) ⇒ void #reload(socket, opts = {}) ⇒ void #reload(sockets, opts = {}) ⇒ void
This method returns an undefined value.
91 92 93 |
# File 'lib/parallel_server/prefork.rb', line 91 def reload(*args) @reload_args = parse_args(*args) end |
#start {|sock, addr, child| ... } ⇒ void
This method returns an undefined value.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/parallel_server/prefork.rb', line 60 def start(&block) raise 'block required' unless block @block = block unless @sockets @sockets = create_server_socket(@host, @port, @listen_backlog) @sockets_created = true end @reload_args = nil while @loop do_reload if @reload_args watch_children adjust_children end ensure @sockets.each{|s| s.close rescue nil} if @sockets && @sockets_created @to_child.values.each{|s| s.close rescue nil} @to_child.clear Timeout.timeout(1){wait_all_children} rescue Thread.new{wait_all_children} end |
#stop ⇒ void
96 97 98 |
# File 'lib/parallel_server/prefork.rb', line 96 def stop @loop = false end |
#stop! ⇒ void
101 102 103 104 |
# File 'lib/parallel_server/prefork.rb', line 101 def stop! Process.kill 'TERM', *@children rescue nil @loop = false end |