reifier 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +31 -2
- data/README.md +9 -2
- data/Rakefile +1 -1
- data/examples/reifier.rb +1 -1
- data/lib/rack/handler/reifier.rb +4 -2
- data/lib/reifier/server.rb +49 -25
- data/lib/reifier/version.rb +1 -1
- data/lib/reifier.rb +2 -1
- data/reifier.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f44cae18b405a8793f34980692b85438987551d7
|
4
|
+
data.tar.gz: 8dad6a8d76982c62fe8ef97bff274c130c7fd310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7c3111aef5ed045e12b832778d60eadbff4783dd99f6e00f1ac98f060d71f6e35e6e32f4f35cbb8e3abc1443203e2b033039119b0cea4a2151456af30d19575
|
7
|
+
data.tar.gz: 24be8d505dc28cc4c594f4d40c90a6aae43b2da86c5545d842240074662f374a40a186f13c819994129eadd9b00a5a264fa94072c3142575088fe7a1794239eb
|
data/.travis.yml
CHANGED
@@ -1,4 +1,33 @@
|
|
1
|
-
|
1
|
+
cache: bundler
|
2
|
+
sudo: false
|
3
|
+
|
4
|
+
before_install:
|
5
|
+
- gem install bundler
|
6
|
+
|
2
7
|
rvm:
|
3
8
|
- 2.2.4
|
4
|
-
|
9
|
+
- 2.3.0
|
10
|
+
- ruby-head
|
11
|
+
- jruby-9000
|
12
|
+
- rbx-3
|
13
|
+
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: ruby-head
|
17
|
+
- rvm: rbx-3
|
18
|
+
- rvm: jruby-9000
|
19
|
+
|
20
|
+
script:
|
21
|
+
- CODECLIMATE_REPO_TOKEN=b84ce34b20f2a809814493585d027aa71ab07e13116bf68430511548815d9411 bundle exec rake
|
22
|
+
|
23
|
+
addons:
|
24
|
+
code_climate:
|
25
|
+
repo_token: b84ce34b20f2a809814493585d027aa71ab07e13116bf68430511548815d9411
|
26
|
+
|
27
|
+
notifications:
|
28
|
+
email:
|
29
|
+
recipients:
|
30
|
+
- benny.klotz92@gmail.com
|
31
|
+
email:
|
32
|
+
on_failure: change
|
33
|
+
on_success: change
|
data/README.md
CHANGED
@@ -8,6 +8,13 @@ reify
|
|
8
8
|
|
9
9
|
Reifier is a threaded and pre forked rack app server written in pure ruby.
|
10
10
|
|
11
|
+
[![Gem Version](https://badge.fury.io/rb/reifier.svg)](https://badge.fury.io/rb/reifier)
|
12
|
+
[![Build Status](https://travis-ci.org/tak1n/reifier.svg?branch=master)](https://travis-ci.org/tak1n/reifier)
|
13
|
+
[![Code Climate](https://codeclimate.com/github/tak1n/reifier/badges/gpa.svg)](https://codeclimate.com/github/tak1n/reifier)
|
14
|
+
[![Test Coverage](https://codeclimate.com/github/tak1n/reifier/badges/coverage.svg)](https://codeclimate.com/github/tak1n/reifier/coverage)
|
15
|
+
[![Inline docs](http://inch-ci.org/github/tak1n/reifier.svg?branch=master)](http://inch-ci.org/github/tak1n/reifier)
|
16
|
+
[![Dependency Status](https://gemnasium.com/tak1n/reifier.svg)](https://gemnasium.com/tak1n/reifier)
|
17
|
+
|
11
18
|
## Is it any good?
|
12
19
|
|
13
20
|
[Yes](http://news.ycombinator.com/item?id=3067434), no really just a fun project use it in production if you want :P
|
@@ -41,9 +48,9 @@ Use it through rackup:
|
|
41
48
|
|
42
49
|
## Available Options
|
43
50
|
|
44
|
-
You can adapt the ThreadPool size with following
|
51
|
+
You can adapt the ThreadPool size with following options:
|
45
52
|
|
46
|
-
$ rackup -s reifier -O
|
53
|
+
$ rackup -s reifier -O MinThreads=8 -O MaxThreads=16
|
47
54
|
|
48
55
|
Also the amount of workers is adaptable:
|
49
56
|
|
data/Rakefile
CHANGED
data/examples/reifier.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
threads 8 # Using a thread pool size of 8
|
1
|
+
threads 8, 16 # Using a thread pool size of 8
|
2
2
|
workers 9 # Using 9 worker processes
|
data/lib/rack/handler/reifier.rb
CHANGED
@@ -6,7 +6,8 @@ module Rack
|
|
6
6
|
module Reifier
|
7
7
|
DEFAULT_OPTIONS = {
|
8
8
|
Workers: 1,
|
9
|
-
|
9
|
+
MinThreads: 0,
|
10
|
+
MaxThreads: 16
|
10
11
|
}.freeze
|
11
12
|
|
12
13
|
def self.run(app, options = {})
|
@@ -19,7 +20,8 @@ module Rack
|
|
19
20
|
|
20
21
|
def self.valid_options
|
21
22
|
{
|
22
|
-
'
|
23
|
+
'MinThreads=MINTHREADS' => 'Number of minimal threads (default: 0)',
|
24
|
+
'MaxThreads=MAXTHREADS' => 'Number of minimal threads (default: 16)',
|
23
25
|
'Workers=WORKERS' => 'Number of workers (default: 1)'
|
24
26
|
}
|
25
27
|
end
|
data/lib/reifier/server.rb
CHANGED
@@ -5,6 +5,26 @@ module Reifier
|
|
5
5
|
@options = options
|
6
6
|
end
|
7
7
|
|
8
|
+
def load_configuration
|
9
|
+
if defined?(Rails)
|
10
|
+
path = Rails.root.join('config/reifier.rb')
|
11
|
+
else
|
12
|
+
path = Dir.pwd + '/reifier.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
return unless File.exist?(path)
|
16
|
+
|
17
|
+
lines = File.read(path).split("\n")
|
18
|
+
|
19
|
+
lines.each do |line|
|
20
|
+
eval(line)
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "======= Loaded settings from #{path} =======\n"
|
24
|
+
rescue NoMethodError => e
|
25
|
+
raise UnsupportedOptionError, "Option #{e.name} is not supported from config file"
|
26
|
+
end
|
27
|
+
|
8
28
|
def start
|
9
29
|
server = TCPServer.new(@options[:Host], @options[:Port])
|
10
30
|
|
@@ -25,11 +45,12 @@ module Reifier
|
|
25
45
|
exit
|
26
46
|
end
|
27
47
|
|
48
|
+
puts "# Ruby version: #{RUBY_VERSION}"
|
49
|
+
puts "# Min threads: #{@options[:MinThreads]}, max threads: #{@options[:MaxThreads]}"
|
28
50
|
puts "# Environment: #{@options[:environment]}"
|
29
|
-
puts "# Listening on tcp://#{@options[:Host]}:#{@options[:Port]}"
|
30
|
-
puts "# Master PID: #{Process.pid}"
|
31
|
-
puts "# Number of Threads used: #{@options[:Threads]}"
|
32
51
|
puts "# Number of Workers used: #{@options[:Workers]}"
|
52
|
+
puts "# Master PID: #{Process.pid}"
|
53
|
+
puts "# Listening on tcp://#{server.addr.last}:#{@options[:Port]}"
|
33
54
|
|
34
55
|
loop do
|
35
56
|
pid = Process.wait
|
@@ -40,38 +61,39 @@ module Reifier
|
|
40
61
|
end
|
41
62
|
end
|
42
63
|
|
43
|
-
|
44
|
-
if defined?(Rails)
|
45
|
-
path = Rails.root.join('config/reifier.rb')
|
46
|
-
else
|
47
|
-
path = Dir.pwd + '/reifier.rb'
|
48
|
-
end
|
49
|
-
|
50
|
-
return unless File.exist?(path)
|
51
|
-
|
52
|
-
lines = File.read(path).split("\n")
|
53
|
-
|
54
|
-
lines.each do |line|
|
55
|
-
option = line.split.first.capitalize
|
56
|
-
value = line.split.last
|
57
|
-
|
58
|
-
@options[option.to_sym] = value
|
59
|
-
end
|
64
|
+
private
|
60
65
|
|
61
|
-
|
66
|
+
def threads(min, max)
|
67
|
+
@options[:MinThreads] = min
|
68
|
+
@options[:MaxThreads] = max
|
62
69
|
end
|
63
70
|
|
64
|
-
|
71
|
+
def workers(count)
|
72
|
+
@options[:Workers] = count
|
73
|
+
end
|
65
74
|
|
66
75
|
def spawn_worker(server)
|
67
76
|
fork do
|
68
|
-
pool
|
77
|
+
pool = Concurrent::ThreadPoolExecutor.new(
|
78
|
+
min_threads: @options[:MinThreads],
|
79
|
+
max_threads: @options[:MaxThreads],
|
80
|
+
max_queue: 0,
|
81
|
+
fallback_policy: :caller_runs,
|
82
|
+
)
|
83
|
+
|
84
|
+
# Signal.trap 'SIGINT' do
|
85
|
+
# puts "Shutting down thread pool in Worker: #{Process.pid}"
|
86
|
+
# pool.shutdown
|
87
|
+
# pool.wait_for_termination
|
88
|
+
|
89
|
+
# exit
|
90
|
+
# end
|
69
91
|
|
70
92
|
loop do
|
71
93
|
socket = server.accept
|
72
94
|
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
73
95
|
|
74
|
-
|
96
|
+
Concurrent::Future.new(executor: pool) do
|
75
97
|
begin
|
76
98
|
request = Request.new(socket, @options)
|
77
99
|
response = Response.new(socket)
|
@@ -82,6 +104,8 @@ module Reifier
|
|
82
104
|
response << @app.call(request.rack_env)
|
83
105
|
|
84
106
|
response.handle
|
107
|
+
rescue EOFError
|
108
|
+
# nothing, shit happens
|
85
109
|
rescue Exception => e
|
86
110
|
socket.close
|
87
111
|
|
@@ -90,7 +114,7 @@ module Reifier
|
|
90
114
|
STDERR.puts e.backtrace
|
91
115
|
STDERR.puts ERROR_FOOTER
|
92
116
|
end
|
93
|
-
end
|
117
|
+
end.execute
|
94
118
|
end
|
95
119
|
end
|
96
120
|
end
|
data/lib/reifier/version.rb
CHANGED
data/lib/reifier.rb
CHANGED
@@ -79,7 +79,8 @@ module Reifier
|
|
79
79
|
POST = 'POST'.freeze
|
80
80
|
PUT = 'PUT'.freeze
|
81
81
|
|
82
|
-
HTTPParseError
|
82
|
+
HTTPParseError = Class.new(StandardError)
|
83
|
+
UnsupportedOptionError = Class.new(StandardError)
|
83
84
|
ERROR_HEADER = '=============================== FATAL SERVER ERROR =============================='.freeze
|
84
85
|
ERROR_FOOTER = "=================================================================================\n\n\n".freeze
|
85
86
|
end
|
data/reifier.gemspec
CHANGED
@@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
|
37
37
|
spec.add_development_dependency 'rubocop', '~> 0.37'
|
38
38
|
spec.add_development_dependency 'rack', '~> 2.0.0.alpha'
|
39
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
39
40
|
end
|
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.5.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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 2.0.0.alpha
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: codeclimate-test-reporter
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: A threaded and preforked rack app server written in pure ruby
|
126
140
|
email:
|
127
141
|
- benny.klotz92@gmail.com
|