prefork_engine 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changes +4 -0
- data/lib/prefork_engine.rb +19 -19
- data/lib/prefork_engine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d61cdcde16f3e999e4fb7335f9f799bec53dd4ec
|
4
|
+
data.tar.gz: aca8bdb8dde327a138f9d3291f998c3aecbdc004
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d9b252d0eee1b472bc81c01fd76b367ad354637466018dd6367f55780d17289056bbd3d13b45d726d07b3003d4fe2089c322ef94fafa7e8c604d80ae3c4e8c9
|
7
|
+
data.tar.gz: 099b01f4de3e829ef010bc34519ac2fcd7665ff8a77bb8f67a054d55756a80588cff5a5b3e4f8a52bddc886743736c490341e0198910f537b3557f8f5075a4f7
|
data/Changes
CHANGED
data/lib/prefork_engine.rb
CHANGED
@@ -26,13 +26,13 @@ class PreforkEngine
|
|
26
26
|
@worker_pids = {}
|
27
27
|
@delayed_task = nil
|
28
28
|
@options["trap_signals"].each do |k,kv|
|
29
|
-
Signal.trap(k)
|
29
|
+
Signal.trap(k) do |signo|
|
30
30
|
@signal_received = Signal.signame(signo)
|
31
|
-
|
31
|
+
end
|
32
32
|
end
|
33
|
-
Signal.trap("CHLD")
|
33
|
+
Signal.trap("CHLD") do
|
34
34
|
#do nothing
|
35
|
-
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def start(&block)
|
@@ -44,9 +44,9 @@ class PreforkEngine
|
|
44
44
|
# main loop
|
45
45
|
while @signal_received.length == 0
|
46
46
|
action = self._decide_action() if @_no_adjust_until <= Time.now.to_f
|
47
|
-
if action > 0
|
47
|
+
if action > 0
|
48
48
|
# start a new worker
|
49
|
-
if @options["before_fork"]
|
49
|
+
if @options["before_fork"]
|
50
50
|
@options["before_fork"].call(self)
|
51
51
|
end
|
52
52
|
pid = nil
|
@@ -54,11 +54,11 @@ class PreforkEngine
|
|
54
54
|
pid = fork
|
55
55
|
rescue => e
|
56
56
|
# fork failed
|
57
|
-
warn "fork failed:#{e}"
|
57
|
+
warn "fork failed:#{e}"
|
58
58
|
self._update_spawn_delay(@options["err_respawn_interval"])
|
59
59
|
next
|
60
60
|
end
|
61
|
-
if pid == nil
|
61
|
+
if pid == nil
|
62
62
|
@in_child = true
|
63
63
|
@options["trap_signals"].each do |k,kv|
|
64
64
|
## Signal.trap(k, 0) #XXX in rspec only?
|
@@ -70,30 +70,30 @@ class PreforkEngine
|
|
70
70
|
exit!(true)
|
71
71
|
end
|
72
72
|
# parent
|
73
|
-
if @options["after_fork"]
|
73
|
+
if @options["after_fork"]
|
74
74
|
@options["after_fork"].call(self)
|
75
75
|
end
|
76
76
|
@worker_pids[pid] = @generation
|
77
77
|
self._update_spawn_delay(@options["spawn_interval"])
|
78
78
|
end
|
79
|
-
if r = self._wait()
|
79
|
+
if r = self._wait()
|
80
80
|
self._on_child_reap(r.pid, r.status)
|
81
|
-
if @worker_pids.delete(r.pid) == @generation && r.status != 0
|
81
|
+
if @worker_pids.delete(r.pid) == @generation && r.status != 0
|
82
82
|
self._update_spawn_delay(@options["err_respawn_interval"])
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
# send signals to workers
|
88
|
-
if action = self._action_for(@signal_received)
|
88
|
+
if action = self._action_for(@signal_received)
|
89
89
|
sig = action[0]
|
90
90
|
interval = action[1]
|
91
|
-
if interval > 0
|
91
|
+
if interval > 0
|
92
92
|
pids = @worker_pids.keys.sort
|
93
93
|
@delayed_task = proc {
|
94
94
|
pid = pids.shift
|
95
95
|
Process.kill(sig, pid)
|
96
|
-
if pids.empty?
|
96
|
+
if pids.empty?
|
97
97
|
@delayed_task = nil
|
98
98
|
@delayed_task_at = nil
|
99
99
|
else
|
@@ -125,7 +125,7 @@ class PreforkEngine
|
|
125
125
|
end #_decide_action
|
126
126
|
|
127
127
|
def _on_child_reap(pid,status)
|
128
|
-
if @options["on_child_reap"]
|
128
|
+
if @options["on_child_reap"]
|
129
129
|
@options["on_child_reap"].call(pid,status)
|
130
130
|
end
|
131
131
|
end
|
@@ -133,7 +133,7 @@ class PreforkEngine
|
|
133
133
|
def _handle_delayed_task
|
134
134
|
while true
|
135
135
|
return nil if !@delayed_task
|
136
|
-
timeleft = @delayed_task_at - Time.now.to_f
|
136
|
+
timeleft = @delayed_task_at - Time.now.to_f
|
137
137
|
return timeleft if timeleft > 0
|
138
138
|
@delayed_task.call
|
139
139
|
end
|
@@ -149,8 +149,8 @@ class PreforkEngine
|
|
149
149
|
def wait_all_children
|
150
150
|
#XXX todo timeout
|
151
151
|
while !@worker_pids.keys.empty?
|
152
|
-
if r = self._wait()
|
153
|
-
if @worker_pids.delete(r.pid)
|
152
|
+
if r = self._wait()
|
153
|
+
if @worker_pids.delete(r.pid)
|
154
154
|
self._on_child_reap(r.pid, r.status)
|
155
155
|
end
|
156
156
|
end
|
@@ -168,7 +168,7 @@ class PreforkEngine
|
|
168
168
|
delayed_fork_sleep = self._decide_action > 0 ? [@_no_adjust_until - Time.now.to_f,0].max : nil
|
169
169
|
sleep_secs = [delayed_task_sleep,delayed_fork_sleep,self._max_wait].select {|v| v != nil}
|
170
170
|
begin
|
171
|
-
if sleep_secs.min != nil
|
171
|
+
if sleep_secs.min != nil
|
172
172
|
sleep(sleep_secs.min)
|
173
173
|
# nonblock
|
174
174
|
return Process.wait3(1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prefork_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Nagano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|