rhebok 0.1.2 → 0.2.0
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 +5 -0
- data/README.md +75 -5
- data/lib/rack/handler/rhebok.rb +18 -1
- data/lib/rhebok/config.rb +71 -0
- data/lib/rhebok/version.rb +1 -1
- data/test/spec_04_hook.rb +39 -0
- data/test/spec_05_config.rb +36 -0
- data/test/testconfig.rb +9 -0
- data/test/testrequest.rb +2 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 352364eef1390ca74ce23d703ef8b1e0c5f61973
|
4
|
+
data.tar.gz: 124b53abfdbb2c8b3b419e1de3b19ef32d579ea7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb08e008694d337388b70d95d6d00bbe4e58df13c74818af1b9f5b4965e7129867cca5a84eac30b7bf46d233bcc7066d8aef9ef05d5b292a8af9c130b5d2f2fc
|
7
|
+
data.tar.gz: 051d9924237070aa7745f2b3daec76738c851cbc3ae70ab543158d6cba6557d6c8369fb0bb19b11073d04f23c06b8a18da56f6669690cfdef1a4efc95085c867
|
data/Changes
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ Or install it yourself as:
|
|
32
32
|
|
33
33
|
## Usage
|
34
34
|
|
35
|
-
$ rackup -s Rhebok
|
35
|
+
$ rackup -s Rhebok --port 8080 -O MaxWorkers=5 -O MaxRequestPerChild=1000 -O OobGC=yes -E production config.ru
|
36
36
|
|
37
37
|
## Sample configuration with Nginx
|
38
38
|
|
@@ -55,10 +55,14 @@ nginx.conf
|
|
55
55
|
command line of running Rhebok
|
56
56
|
|
57
57
|
$ start_server --path /path/to/app.sock --backlog 16384 -- rackup -s Rhebok \
|
58
|
-
-O MaxWorkers=
|
58
|
+
-O MaxWorkers=5 -O MaxRequestPerChild=1000 -E production config.ru
|
59
59
|
|
60
60
|
## Options
|
61
61
|
|
62
|
+
### ConfigFile
|
63
|
+
|
64
|
+
filename to load options. For details, please read `Config File` section
|
65
|
+
|
62
66
|
### Host
|
63
67
|
|
64
68
|
hostname or ip address to bind (default: 0.0.0.0)
|
@@ -77,7 +81,7 @@ specifies a listen backlog parameter
|
|
77
81
|
|
78
82
|
### MaxWorkers
|
79
83
|
|
80
|
-
number of worker processes (default:
|
84
|
+
number of worker processes (default: 5)
|
81
85
|
|
82
86
|
### MaxRequestPerChild
|
83
87
|
|
@@ -108,7 +112,73 @@ If set, randomizes the number of request before invoking GC between the number o
|
|
108
112
|
|
109
113
|
### SpawnInterval
|
110
114
|
|
111
|
-
if set, worker processes will not be spawned more than once than every given seconds. Also, when
|
115
|
+
if set, worker processes will not be spawned more than once than every given seconds. Also, when SIGUSR1 is being received, no more than one worker processes will be collected every given seconds. This feature is useful for doing a "slow-restart". See http://blog.kazuhooku.com/2011/04/web-serverstarter-parallelprefork.html for more information. (default: none)
|
116
|
+
|
117
|
+
## Config File
|
118
|
+
|
119
|
+
load options from specified config file. If same options are exists in command line and the config file, options written in the config file will take precedence.
|
120
|
+
|
121
|
+
```
|
122
|
+
$ cat rhebok_config.rb
|
123
|
+
host '127.0.0.1'
|
124
|
+
port 9292
|
125
|
+
max_workers ENV["WEB_CONCURRENCY"] || 3
|
126
|
+
before_fork {
|
127
|
+
defined?(ActiveRecord::Base) and
|
128
|
+
ActiveRecord::Base.connection.disconnect!
|
129
|
+
}
|
130
|
+
after_fork {
|
131
|
+
defined?(ActiveRecord::Base) and
|
132
|
+
ActiveRecord::Base.establish_connection
|
133
|
+
}
|
134
|
+
$ rackup -s Rhebok -O ConfigFile=rhebok_config.rb -O port 8080 -O OobGC -E production
|
135
|
+
Rhebok starts Listening on 127.0.0.1:9292 Pid:11892
|
136
|
+
```
|
137
|
+
|
138
|
+
Supported options in config file are below.
|
139
|
+
|
140
|
+
### host
|
141
|
+
|
142
|
+
### port
|
143
|
+
|
144
|
+
### path
|
145
|
+
|
146
|
+
### backlog
|
147
|
+
|
148
|
+
### max_workers
|
149
|
+
|
150
|
+
### timeout
|
151
|
+
|
152
|
+
### max_request_per_child
|
153
|
+
|
154
|
+
### min_request_per_child
|
155
|
+
|
156
|
+
### oobgc
|
157
|
+
|
158
|
+
### max_gc_per_request
|
159
|
+
|
160
|
+
### min_gc_per_request
|
161
|
+
|
162
|
+
### spawn_interval
|
163
|
+
|
164
|
+
### before_fork
|
165
|
+
|
166
|
+
proc object. This block will be called by a master process before forking each worker
|
167
|
+
|
168
|
+
### after_fork
|
169
|
+
|
170
|
+
proc object. This block will be called by a worker process after forking
|
171
|
+
|
172
|
+
## Signal Handling
|
173
|
+
|
174
|
+
### Master process
|
175
|
+
|
176
|
+
- TERM, HUP: If the master process received TERM or HUP signal, Rhebok will shutdown gracefully
|
177
|
+
- USR1: If set SpawnInterval, Rhebok will collect workers every given seconds and exit
|
178
|
+
|
179
|
+
### worker process
|
180
|
+
|
181
|
+
- TERM: If the worker process received TERM, exit after finishing current request
|
112
182
|
|
113
183
|
## Benchmark
|
114
184
|
|
@@ -162,7 +232,7 @@ config.ru
|
|
162
232
|
command to run
|
163
233
|
|
164
234
|
$ start_server --path /path/to/app.sock -- rackup -s Rhebok \
|
165
|
-
-O MaxWorkers=8 -O MaxRequestPerChild=
|
235
|
+
-O MaxWorkers=8 -O MaxRequestPerChild=0 -E production config.ru
|
166
236
|
|
167
237
|
result
|
168
238
|
|
data/lib/rack/handler/rhebok.rb
CHANGED
@@ -10,6 +10,7 @@ require 'rack/utils'
|
|
10
10
|
require 'io/nonblock'
|
11
11
|
require 'prefork_engine'
|
12
12
|
require 'rhebok'
|
13
|
+
require 'rhebok/config'
|
13
14
|
|
14
15
|
$RACK_HANDLER_RHEBOK_GCTOOL = true
|
15
16
|
begin
|
@@ -26,7 +27,7 @@ module Rack
|
|
26
27
|
:Host => '0.0.0.0',
|
27
28
|
:Port => 9292,
|
28
29
|
:Path => nil,
|
29
|
-
:MaxWorkers =>
|
30
|
+
:MaxWorkers => 5,
|
30
31
|
:Timeout => 300,
|
31
32
|
:MaxRequestPerChild => 1000,
|
32
33
|
:MinRequestPerChild => nil,
|
@@ -36,6 +37,8 @@ module Rack
|
|
36
37
|
:MaxGCPerRequest => 5,
|
37
38
|
:MinGCPerRequest => nil,
|
38
39
|
:BackLog => nil,
|
40
|
+
:BeforeFork => nil,
|
41
|
+
:AfterFork => nil,
|
39
42
|
}
|
40
43
|
NULLIO = StringIO.new("").set_encoding('BINARY')
|
41
44
|
|
@@ -57,6 +60,12 @@ module Rack
|
|
57
60
|
options[:OobGC] = options[:OobGC].match(/^(true|yes|1)$/i) ? true : false
|
58
61
|
end
|
59
62
|
@options = DEFAULT_OPTIONS.merge(options)
|
63
|
+
if @options[:ConfigFile] != nil
|
64
|
+
puts "loading from config_file:#{options[:ConfigFile]}"
|
65
|
+
config = ::Rhebok::Config.new
|
66
|
+
config.instance_eval(::File.read @options.delete(:ConfigFile))
|
67
|
+
@options.merge!(config.retrieve)
|
68
|
+
end
|
60
69
|
@server = nil
|
61
70
|
@_is_tcp = false
|
62
71
|
@_using_defer_accept = false
|
@@ -127,12 +136,20 @@ module Rack
|
|
127
136
|
if @options[:ErrRespawnInterval]
|
128
137
|
pm_args["err_respawn_interval"] = @options[:ErrRespawnInterval].to_i
|
129
138
|
end
|
139
|
+
if @options[:BeforeFork]
|
140
|
+
pm_args["before_fork"] = proc { |pe2|
|
141
|
+
@options[:BeforeFork].call
|
142
|
+
}
|
143
|
+
end
|
130
144
|
Signal.trap('INT','SYSTEM_DEFAULT') # XXX
|
131
145
|
|
132
146
|
pe = PreforkEngine.new(pm_args)
|
133
147
|
while !pe.signal_received.match(/^(TERM|USR1)$/)
|
134
148
|
pe.start do
|
135
149
|
srand
|
150
|
+
if @options[:AfterFork]
|
151
|
+
@options[:AfterFork].call
|
152
|
+
end
|
136
153
|
self.accept_loop(app)
|
137
154
|
end
|
138
155
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Rhebok
|
2
|
+
class Config
|
3
|
+
def initialize(options={})
|
4
|
+
@config = options
|
5
|
+
end
|
6
|
+
|
7
|
+
def host(val)
|
8
|
+
@config[:Host] = val
|
9
|
+
end
|
10
|
+
|
11
|
+
def port(val)
|
12
|
+
@config[:Port] = val
|
13
|
+
end
|
14
|
+
|
15
|
+
def path(val)
|
16
|
+
@config[:Path] = val
|
17
|
+
end
|
18
|
+
|
19
|
+
def max_workers(val)
|
20
|
+
@config[:MaxWorkers] = val
|
21
|
+
end
|
22
|
+
|
23
|
+
def timeout(val)
|
24
|
+
@config[:Timeout] = val
|
25
|
+
end
|
26
|
+
|
27
|
+
def max_request_per_child(val)
|
28
|
+
@config[:MaxRequestPerChild] = val
|
29
|
+
end
|
30
|
+
|
31
|
+
def min_request_per_child(val)
|
32
|
+
@config[:MinRequestPerChild] = val
|
33
|
+
end
|
34
|
+
|
35
|
+
def spawn_interval(val)
|
36
|
+
@config[:SpawnInterval] = val
|
37
|
+
end
|
38
|
+
|
39
|
+
def err_respawn_interval(val)
|
40
|
+
@config[:ErrRespawnInterval] = val
|
41
|
+
end
|
42
|
+
|
43
|
+
def oobgc(val)
|
44
|
+
@config[:OobGC] = val
|
45
|
+
end
|
46
|
+
|
47
|
+
def max_gc_per_request(val)
|
48
|
+
@config[:MaxGCPerRequest] = val
|
49
|
+
end
|
50
|
+
|
51
|
+
def min_gc_per_request(val)
|
52
|
+
@config[:MinGCPerRequest] = val
|
53
|
+
end
|
54
|
+
|
55
|
+
def backlog(val)
|
56
|
+
@config[:BackLog] = val
|
57
|
+
end
|
58
|
+
|
59
|
+
def before_fork(&block)
|
60
|
+
@config[:BeforeFork] = block
|
61
|
+
end
|
62
|
+
|
63
|
+
def after_fork(&block)
|
64
|
+
@config[:AfterFork] = block
|
65
|
+
end
|
66
|
+
|
67
|
+
def retrieve
|
68
|
+
@config
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/rhebok/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require File.expand_path('../testrequest', __FILE__)
|
3
|
+
require 'timeout'
|
4
|
+
require 'rack/handler/rhebok'
|
5
|
+
|
6
|
+
describe Rhebok do
|
7
|
+
extend TestRequest::Helpers
|
8
|
+
begin
|
9
|
+
|
10
|
+
@host = '127.0.0.1'
|
11
|
+
@port = 9202
|
12
|
+
@app = Rack::Lint.new(TestRequest.new)
|
13
|
+
@pid = fork
|
14
|
+
if @pid == nil
|
15
|
+
#child
|
16
|
+
Rack::Handler::Rhebok.run(@app, :Host=>'127.0.0.1', :Port=>9202, :MaxWorkers=>1,
|
17
|
+
:BeforeFork => proc { ENV["TEST_FOO"] = "FOO" },
|
18
|
+
:AfterFork => proc { ENV["TEST_BAR"] = "BAR" },
|
19
|
+
)
|
20
|
+
exit!(true)
|
21
|
+
end
|
22
|
+
sleep 1
|
23
|
+
|
24
|
+
# test
|
25
|
+
should "hook env" do
|
26
|
+
GET("/")
|
27
|
+
response["TEST_FOO"].should.equal "FOO"
|
28
|
+
response["TEST_BAR"].should.equal "BAR"
|
29
|
+
end
|
30
|
+
|
31
|
+
ensure
|
32
|
+
sleep 1
|
33
|
+
if @pid != nil
|
34
|
+
Process.kill(:TERM, @pid)
|
35
|
+
Process.wait()
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require File.expand_path('../testrequest', __FILE__)
|
3
|
+
require 'timeout'
|
4
|
+
require 'rack/handler/rhebok'
|
5
|
+
|
6
|
+
describe Rhebok do
|
7
|
+
extend TestRequest::Helpers
|
8
|
+
begin
|
9
|
+
|
10
|
+
@host = '127.0.0.1'
|
11
|
+
@port = 9202
|
12
|
+
@app = Rack::Lint.new(TestRequest.new)
|
13
|
+
@pid = fork
|
14
|
+
if @pid == nil
|
15
|
+
#child
|
16
|
+
Rack::Handler::Rhebok.run(@app, :BeforeFork=>proc { ENV["TEST_FOO"]="BAZ" }, :ConfigFile=>File.expand_path('../testconfig.rb', __FILE__))
|
17
|
+
exit!(true)
|
18
|
+
end
|
19
|
+
sleep 1
|
20
|
+
|
21
|
+
# test
|
22
|
+
should "hook env" do
|
23
|
+
GET("/")
|
24
|
+
response["TEST_FOO"].should.equal "FOO"
|
25
|
+
response["TEST_BAR"].should.equal "BAR"
|
26
|
+
end
|
27
|
+
|
28
|
+
ensure
|
29
|
+
sleep 1
|
30
|
+
if @pid != nil
|
31
|
+
Process.kill(:TERM, @pid)
|
32
|
+
Process.wait()
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/test/testconfig.rb
ADDED
data/test/testrequest.rb
CHANGED
@@ -19,6 +19,8 @@ class TestRequest
|
|
19
19
|
minienv = env.dup
|
20
20
|
# This may in the future want to replace with a dummy value instead.
|
21
21
|
minienv.delete_if { |k,v| NOSERIALIZE.any? { |c| v.kind_of?(c) } }
|
22
|
+
ENV.has_key?("TEST_FOO") and minienv["TEST_FOO"] = ENV["TEST_FOO"]
|
23
|
+
ENV.has_key?("TEST_BAR") and minienv["TEST_BAR"] = ENV["TEST_BAR"]
|
22
24
|
body = minienv.to_yaml
|
23
25
|
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
|
24
26
|
res_header = {"Content-Type" => "text/yaml", "Content-Length" => size.to_s, "X-Foo" => "Foo\nBar", "X-Bar"=>"Foo\n\nBar", "X-Baz"=>"\nBaz", "X-Fuga"=>"Fuga\n"}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhebok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,11 +109,15 @@ files:
|
|
109
109
|
- ext/rhebok/rhebok.c
|
110
110
|
- lib/rack/handler/rhebok.rb
|
111
111
|
- lib/rhebok.rb
|
112
|
+
- lib/rhebok/config.rb
|
112
113
|
- lib/rhebok/version.rb
|
113
114
|
- rhebok.gemspec
|
114
115
|
- test/spec_01_basic.rb
|
115
116
|
- test/spec_02_server.rb
|
116
117
|
- test/spec_03_unix.rb
|
118
|
+
- test/spec_04_hook.rb
|
119
|
+
- test/spec_05_config.rb
|
120
|
+
- test/testconfig.rb
|
117
121
|
- test/testrequest.rb
|
118
122
|
homepage: https://github.com/kazeburo/rhebok
|
119
123
|
licenses:
|
@@ -143,4 +147,7 @@ test_files:
|
|
143
147
|
- test/spec_01_basic.rb
|
144
148
|
- test/spec_02_server.rb
|
145
149
|
- test/spec_03_unix.rb
|
150
|
+
- test/spec_04_hook.rb
|
151
|
+
- test/spec_05_config.rb
|
152
|
+
- test/testconfig.rb
|
146
153
|
- test/testrequest.rb
|