reifier 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9851d78945b3c347db66a2abaf1226e042250e8
4
- data.tar.gz: e3995204dda21f2d7b920f62f5015af09fef0b24
3
+ metadata.gz: c728b806deb19da5dcfa300f0a686b0981d369d8
4
+ data.tar.gz: 8f9b2057ca56169779e32e71037f12df61bacd4c
5
5
  SHA512:
6
- metadata.gz: fd6c52d68405d750ba5ea58b0bb8fbfb919479113dedea8896f1b459a586b1564a42fb0e5e6575e3505eaf19ce95b29d7abd36e13307b47684366c986be2b5c7
7
- data.tar.gz: 53015621be965b1e53ae5b499fb1728a320617850136e9d8e2d5f246a15de6db3870898e6ca2f53bad026b5abcdf90863a39f31fa877d53c5c588eb185d955a2
6
+ metadata.gz: b63257d7a6c23bfaadddfa3e0f11e9905d8ce5c0059ef7444db6259f62591076f8a1f240fe49fa0c326411eb9db99c84f3bc68454c186b0505b798c56e50a231
7
+ data.tar.gz: 0717702206a003c2749e7dd018928a3ad68a71635e78e1300ba18396762a38c7f1dc9128c83dd9efe5a036ee0e7aba556e9ef0e99a96277974b5e9f3b73dc321
data/README.md CHANGED
@@ -6,6 +6,15 @@ reify
6
6
 
7
7
  (transitive) to consider or make (an abstract idea or concept) real or concrete
8
8
 
9
+ ## Is it any good?
10
+
11
+ [Yes](http://news.ycombinator.com/item?id=3067434), no really just a fun project use it in production when u want :P
12
+
13
+ ## Y u no benchmark?!
14
+
15
+ Benchmarking a non feature complete HTTP server is very reasonable but here it is:
16
+ [benchmarky marky](https://gist.github.com/tak1n/90c8d59111f0f9a3cd36)
17
+
9
18
  ## Installation
10
19
 
11
20
  Add this line to your application's Gemfile:
@@ -32,7 +41,11 @@ Use it through rackup:
32
41
 
33
42
  You can adapt the ThreadPool sized with following option:
34
43
 
35
- $ rackup -s reifier -O Threads=16
44
+ $ rackup -s reifier -O Threads=8
45
+
46
+ Also the amount of workers is adaptable:
47
+
48
+ $ rackup -s reifier -O Workers=5
36
49
 
37
50
  ## Development
38
51
 
@@ -4,7 +4,13 @@ require 'reifier'
4
4
  module Rack
5
5
  module Handler
6
6
  module Reifier
7
+ DEFAULT_OPTIONS = {
8
+ Workers: 3,
9
+ Threads: 16
10
+ }.freeze
11
+
7
12
  def self.run(app, options = {})
13
+ options = DEFAULT_OPTIONS.merge(options)
8
14
  puts "Reifier #{::Reifier::VERSION} starting.."
9
15
  server = ::Reifier::Server.new(app, options)
10
16
  server.start
@@ -6,50 +6,74 @@ module Reifier
6
6
  end
7
7
 
8
8
  def start
9
- Thread.abort_on_exception = true
10
- Signal.trap 'SIGINT' do
11
- puts "\nCleaning up nothing for now..."
12
- exit
9
+ server = TCPServer.new(@options[:Host], @options[:Port])
10
+
11
+ child_pids = []
12
+ @options[:Workers].to_i.times do
13
+ child_pids << spawn_worker(server)
13
14
  end
14
15
 
15
- server = TCPServer.new(@options[:Host], @options[:Port])
16
+ Signal.trap 'SIGINT' do
17
+ puts "Cleaning up #{child_pids.length} Workers"
18
+ child_pids.each do |cpid|
19
+ begin
20
+ Process.kill(:INT, cpid)
21
+ rescue Errno::ESRCH
22
+ end
23
+ end
16
24
 
17
- threads = @options[:Threads] || 5
18
- pool = Concurrent::FixedThreadPool.new(@options[:Threads] || 5)
25
+ exit
26
+ end
19
27
 
20
28
  puts "# Environment: #{@options[:environment]}"
21
29
  puts "# Listening on tcp://#{@options[:Host]}:#{@options[:Port]}"
22
- puts "# PID: #{Process.pid}"
23
- puts "# Number of Threads used: #{threads}"
30
+ puts "# Master PID: #{Process.pid}"
31
+ puts "# Number of Threads used: #{@options[:Threads]}"
32
+ puts "# Number of Workers used: #{@options[:Workers]}"
24
33
 
25
34
  loop do
26
- socket = server.accept
27
- socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
35
+ pid = Process.wait
36
+ STDERR.puts "Process #{pid} crashed"
28
37
 
29
- # Thread.new do
30
- pool.post do
31
- begin
32
- request = Request.new(@options)
33
- response = Response.new
38
+ child_pids.delete(pid)
39
+ child_pids << spawn_worker
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def spawn_worker(server)
46
+ fork do
47
+ Thread.abort_on_exception = true
34
48
 
35
- request.handle(socket)
49
+ pool = Concurrent::FixedThreadPool.new(@options[:Threads])
36
50
 
37
- response.protocol = request.protocol
38
- response << @app.call(request.rack_env)
51
+ loop do
52
+ socket = server.accept
53
+ socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
39
54
 
40
- response.handle(socket)
55
+ pool.post do
56
+ begin
57
+ request = Request.new(@options)
58
+ response = Response.new
41
59
 
42
- log_request request, response if development?
43
- rescue Exception => e
44
- log "\nError: #{e.class}\nMessage: #{e.message}\n\nBacktrace:\n\t#{e.backtrace.join("\n\t")}" if development?
45
- socket.close
60
+ request.handle(socket)
61
+
62
+ response.protocol = request.protocol
63
+ response << @app.call(request.rack_env)
64
+
65
+ response.handle(socket)
66
+
67
+ log_request request, response if development?
68
+ rescue Exception => e
69
+ log "\nError: #{e.class}\nMessage: #{e.message}\n\nBacktrace:\n\t#{e.backtrace.join("\n\t")}" if development?
70
+ socket.close
71
+ end
46
72
  end
47
73
  end
48
74
  end
49
75
  end
50
76
 
51
- private
52
-
53
77
  def development?
54
78
  @options[:environment] == 'development'
55
79
  end
@@ -1,3 +1,3 @@
1
1
  module Reifier
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
data/reifier.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Benny Klotz"]
10
10
  spec.email = ["benny.klotz92@gmail.com"]
11
11
 
12
- spec.summary = %q{A threaded rack app server written in pure ruby}
13
- spec.description = %q{A rack app server written in pure ruby}
12
+ spec.summary = %q{A threaded and preforked rack app server written in pure ruby}
13
+ spec.description = %q{A threaded and preforked rack app server written in pure ruby}
14
14
  spec.homepage = "https://github.com/tak1n/reifier"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benny Klotz
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 2.0.0.alpha
125
- description: A rack app server written in pure ruby
125
+ description: A threaded and preforked rack app server written in pure ruby
126
126
  email:
127
127
  - benny.klotz92@gmail.com
128
128
  executables: []
@@ -168,5 +168,5 @@ rubyforge_project:
168
168
  rubygems_version: 2.5.1
169
169
  signing_key:
170
170
  specification_version: 4
171
- summary: A threaded rack app server written in pure ruby
171
+ summary: A threaded and preforked rack app server written in pure ruby
172
172
  test_files: []