about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-04 20:17:58 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-04 20:38:53 -0700
commite8eb252f64c94eb57532ef3de55d28e5d23e3cd8 (patch)
treecb7222112498789f2df7cd9f0cbc0ef7cf8a9466 /lib
parent9f11d1cec1975f4dcf35c68538243a44a629ed62 (diff)
downloadrainbows-e8eb252f64c94eb57532ef3de55d28e5d23e3cd8.tar.gz
Various concurrency models work and scale differently, pick
counts that make a reasonable amount of sense...
Diffstat (limited to 'lib')
-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)