about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/rainbows.rb17
-rw-r--r--lib/rainbows/http_server.rb2
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index b2c315d..04be9b4 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -13,14 +13,23 @@ module Rainbows
   require 'rainbows/http_response'
   require 'rainbows/base'
 
-  autoload :Revactor, 'rainbows/revactor'
-  autoload :ThreadPool, 'rainbows/thread_pool'
-  autoload :ThreadSpawn, 'rainbows/thread_spawn'
-
   class << self
     def run(app, options = {})
       HttpServer.new(app, options).start.join
     end
   end
 
+  # maps models to default worker counts, default worker count numbers are
+  # pretty arbitrary and tuning them to your application and hardware is
+  # highly recommended
+  MODEL_WORKER_CONNECTIONS = {
+    :Base => 1, # this one can't change
+    :Revactor => 50,
+    :ThreadSpawn => 30,
+    :ThreadPool => 10,
+  }.each do |model, _|
+    u = model.to_s.gsub(/([a-z0-9])([A-Z0-9])/) { "#{$1}_#{$2.downcase!}" }
+    autoload model, "rainbows/#{u.downcase!}"
+  end
+
 end
diff --git a/lib/rainbows/http_server.rb b/lib/rainbows/http_server.rb
index 8fdecb6..0d9ef35 100644
--- a/lib/rainbows/http_server.rb
+++ b/lib/rainbows/http_server.rb
@@ -15,9 +15,9 @@ module Rainbows
 
     def initialize(app, options)
       @@instance = self
-      @worker_connections = 1
       rv = super(app, options)
       defined?(@use) or use(:Base)
+      @worker_connections ||= MODEL_WORKER_CONNECTIONS[@use]
     end
 
     def use(*args)