crap_server 0.0.3.0 → 0.0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b7a2133b068b88f831896a41664b94448243b84
4
- data.tar.gz: 49f6bebeaf9bdb5b51e33a39053630bc47068b40
3
+ metadata.gz: 09f1212512d245febe72024ad1751b4720dbba32
4
+ data.tar.gz: 689ad5316946fbc2a52c48e7fe3b186458d9be27
5
5
  SHA512:
6
- metadata.gz: 9bb7f5661dd2b9b51d96abf188a4038a275ae77a3ff13d4315b6c0ac03c616354bbc91293f8a65df6f2157c01616bc4432fbf1d841143cd7286e8163f3577414
7
- data.tar.gz: 694265fae58d630a42b6b973014590fe1f3ec66e29b300a42f2919d9691b6e987154878e08b5ac6bd980032d38ccdc6358d4614bab3663606c4cf2cb86ce12e3
6
+ metadata.gz: e7888fd1485a6b2c06ade746640b6a94860a25ca099c1cebf0ffb4ea1e48d03dfab1ab2e2ab8b078100e240bc982dac7f37c4c9f79275b853acb0d1d526eff42
7
+ data.tar.gz: e88ea89e7fd1c7b6185f695d61736af723a2707abef6e638d34377acb242e00f93dc5827095e8239522854762105aebcead9785b4d167ae3786a4a86ee8044f4
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Code Climate](https://codeclimate.com/github/anga/crap_server/badges/gpa.svg)](https://codeclimate.com/github/anga/crap_server)
4
4
 
5
5
  Really thin and non intuitive ruby server. Made to be fast and ready for really heavy servers (not only http server).
6
- Use Preforking and Evented pattern.
6
+ Use Preforking, Evented IO and a Thread Pool to handle each connection and prevent get stuck by some slow query.
7
7
 
8
8
  # Another one?
9
9
 
@@ -38,6 +38,9 @@ Or install it yourself as:
38
38
 
39
39
  See all available options in lib/crap_server/configure.rb
40
40
 
41
+ ## Pool size
42
+ By default, the pool size run 10 threads per core. You can change it with the pool_size config option.
43
+
41
44
  # Running our application
42
45
 
43
46
  ruby my_app.rb
@@ -29,7 +29,10 @@ module CrapServer
29
29
  # The log level used
30
30
  attr_accessor :log_level
31
31
  # The timeout using when we use non-blocking method
32
+ # NOT USED
32
33
  attr_accessor :timeout
34
+ # Thread pool size. 10 per cor by default
35
+ attr_accessor :pool_size
33
36
  def initialize
34
37
  @port = 7331
35
38
  @manual_read = false
@@ -40,6 +43,7 @@ module CrapServer
40
43
  @log_file = STDOUT
41
44
  @log_level = Logger::DEBUG
42
45
  @timeout = nil # By default, no timeout. Used to allow persistent connections.
46
+ @pool_size = 10
43
47
  end
44
48
  end
45
49
  end
@@ -45,8 +45,8 @@ module CrapServer
45
45
  def spawn_child
46
46
  fork do
47
47
  begin
48
- handler = CrapServer::ConnectionHandler.new @sockets
49
- handler.handle &@block_proc
48
+ pool = CrapServer::ThreadPool.new @sockets
49
+ pool.run &@block_proc
50
50
  rescue Interrupt
51
51
  end
52
52
  end
@@ -0,0 +1,31 @@
1
+ module CrapServer
2
+ class ThreadPool
3
+ def initialize(sockets)
4
+ @sockets = sockets
5
+ end
6
+
7
+ def run(&block)
8
+ @block = block
9
+ Thread.abort_on_exception = true
10
+ threads = ThreadGroup.new
11
+ config.pool_size.times do
12
+ threads.add spawn_thread
13
+ end
14
+
15
+ sleep
16
+ end
17
+
18
+ protected
19
+
20
+ def spawn_thread
21
+ Thread.new {
22
+ handler = CrapServer::ConnectionHandler.new @sockets
23
+ handler.handle &@block
24
+ }
25
+ end
26
+
27
+ def config
28
+ CrapServer::Application.send(:config)
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module CrapServer
2
- VERSION = '0.0.3.0'
2
+ VERSION = '0.0.4.0'
3
3
  end
data/lib/crap_server.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'crap_server/version'
2
2
  require 'crap_server/configure'
3
+ require 'crap_server/thread_pool'
3
4
  require 'crap_server/forker'
4
5
  require 'crap_server/connection_handler'
5
6
  require 'crap_server/connection_instance'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crap_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.0
4
+ version: 0.0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andres Jose Borek
@@ -58,6 +58,7 @@ files:
58
58
  - lib/crap_server/connection_handler.rb
59
59
  - lib/crap_server/connection_instance.rb
60
60
  - lib/crap_server/forker.rb
61
+ - lib/crap_server/thread_pool.rb
61
62
  - lib/crap_server/version.rb
62
63
  - spec/application_spec.rb
63
64
  - spec/spec_helper.rb