reifier 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/reifier.rb +1 -1
- data/lib/rack/handler/reifier.rb +1 -2
- data/lib/reifier/server.rb +68 -55
- data/lib/reifier/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: b29d21d3efe5c6cd139af6449af8657d3f9d0b84
|
4
|
+
data.tar.gz: 902c73060ba214bb356815e9f2929d88e601b813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7ca642a2d5805356f90afcb4d6a961506ed78457602545c840ee93ded772a286886183569fcc2ecec1b949206607953c8b454f4deb0be918bf3e0432440fe99
|
7
|
+
data.tar.gz: adb27c166f7f22437ee134894a02243f61abbaa0afb2fb99069788758abb967390659fda263d915bfa59bb6aa6fd1216aea3fc6492f2ad83b7311f3b1e4f1261
|
data/examples/reifier.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
threads 8, 16 # Using a thread pool size of 8
|
1
|
+
threads 8, 16 # Using a thread pool min size of 8 and max size of 16
|
2
2
|
workers 9 # Using 9 worker processes
|
data/lib/rack/handler/reifier.rb
CHANGED
@@ -5,7 +5,6 @@ module Rack
|
|
5
5
|
module Handler
|
6
6
|
module Reifier
|
7
7
|
DEFAULT_OPTIONS = {
|
8
|
-
Workers: 1,
|
9
8
|
MinThreads: 0,
|
10
9
|
MaxThreads: 16
|
11
10
|
}.freeze
|
@@ -22,7 +21,7 @@ module Rack
|
|
22
21
|
{
|
23
22
|
'MinThreads=MINTHREADS' => 'Number of minimal threads (default: 0)',
|
24
23
|
'MaxThreads=MAXTHREADS' => 'Number of minimal threads (default: 16)',
|
25
|
-
'Workers=WORKERS'
|
24
|
+
'Workers=WORKERS' => 'Number of workers (default: none)'
|
26
25
|
}
|
27
26
|
end
|
28
27
|
end
|
data/lib/reifier/server.rb
CHANGED
@@ -28,9 +28,40 @@ module Reifier
|
|
28
28
|
def start
|
29
29
|
server = TCPServer.new(@options[:Host], @options[:Port])
|
30
30
|
|
31
|
+
puts "# Ruby version: #{RUBY_VERSION}"
|
32
|
+
puts "# Min threads: #{@options[:MinThreads]}, max threads: #{@options[:MaxThreads]}"
|
33
|
+
puts "# Environment: #{@options[:environment]}"
|
34
|
+
puts "# Master PID: #{Process.pid}"
|
35
|
+
puts "# Listening on tcp://#{server.addr.last}:#{@options[:Port]}"
|
36
|
+
|
37
|
+
if @options[:Workers]
|
38
|
+
start_clustered(server)
|
39
|
+
else
|
40
|
+
start_single(server)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def start_single(server)
|
47
|
+
puts '# Started in single mode'
|
48
|
+
start!(server)
|
49
|
+
end
|
50
|
+
|
51
|
+
def start_clustered(server)
|
52
|
+
puts '# Started in clustered mode'
|
31
53
|
child_pids = []
|
32
|
-
|
33
|
-
|
54
|
+
|
55
|
+
puts '# ================================'
|
56
|
+
puts "# Spinning up #{@options[:Workers].to_i} Workers"
|
57
|
+
@options[:Workers].to_i.times do |i|
|
58
|
+
pid = fork do
|
59
|
+
start!(server)
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "# Worker #{i} started with pid: #{pid}"
|
63
|
+
|
64
|
+
child_pids << pid
|
34
65
|
end
|
35
66
|
|
36
67
|
Signal.trap 'SIGINT' do
|
@@ -45,23 +76,15 @@ module Reifier
|
|
45
76
|
exit
|
46
77
|
end
|
47
78
|
|
48
|
-
puts "# Ruby version: #{RUBY_VERSION}"
|
49
|
-
puts "# Min threads: #{@options[:MinThreads]}, max threads: #{@options[:MaxThreads]}"
|
50
|
-
puts "# Environment: #{@options[:environment]}"
|
51
|
-
puts "# Number of Workers used: #{@options[:Workers]}"
|
52
|
-
puts "# Master PID: #{Process.pid}"
|
53
|
-
puts "# Listening on tcp://#{server.addr.last}:#{@options[:Port]}"
|
54
|
-
|
55
79
|
loop do
|
56
80
|
pid = Process.wait
|
57
81
|
STDERR.puts "Process #{pid} crashed"
|
58
82
|
|
59
83
|
child_pids.delete(pid)
|
60
|
-
child_pids << spawn_worker
|
84
|
+
child_pids << spawn_worker(server)
|
61
85
|
end
|
62
86
|
end
|
63
87
|
|
64
|
-
private
|
65
88
|
|
66
89
|
def threads(min, max)
|
67
90
|
@options[:MinThreads] = min
|
@@ -72,50 +95,40 @@ module Reifier
|
|
72
95
|
@options[:Workers] = count
|
73
96
|
end
|
74
97
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
rescue Exception => e
|
110
|
-
socket.close
|
111
|
-
|
112
|
-
STDERR.puts ERROR_HEADER
|
113
|
-
STDERR.puts "#{e.class}: #{e}"
|
114
|
-
STDERR.puts e.backtrace
|
115
|
-
STDERR.puts ERROR_FOOTER
|
116
|
-
end
|
117
|
-
end.execute
|
118
|
-
end
|
98
|
+
def start!(server)
|
99
|
+
pool = Concurrent::ThreadPoolExecutor.new(
|
100
|
+
min_threads: @options[:MinThreads],
|
101
|
+
max_threads: @options[:MaxThreads],
|
102
|
+
max_queue: 0,
|
103
|
+
fallback_policy: :caller_runs,
|
104
|
+
)
|
105
|
+
|
106
|
+
loop do
|
107
|
+
socket = server.accept
|
108
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
109
|
+
|
110
|
+
Concurrent::Future.new(executor: pool) do
|
111
|
+
begin
|
112
|
+
request = Request.new(socket, @options)
|
113
|
+
response = Response.new(socket)
|
114
|
+
|
115
|
+
request.handle
|
116
|
+
|
117
|
+
response.protocol = request.protocol
|
118
|
+
response << @app.call(request.rack_env)
|
119
|
+
|
120
|
+
response.handle
|
121
|
+
rescue EOFError
|
122
|
+
# nothing, shit happens
|
123
|
+
rescue Exception => e
|
124
|
+
socket.close
|
125
|
+
|
126
|
+
STDERR.puts ERROR_HEADER
|
127
|
+
STDERR.puts "#{e.class}: #{e}"
|
128
|
+
STDERR.puts e.backtrace
|
129
|
+
STDERR.puts ERROR_FOOTER
|
130
|
+
end
|
131
|
+
end.execute
|
119
132
|
end
|
120
133
|
end
|
121
134
|
end
|
data/lib/reifier/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benny Klotz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|