From e8eb252f64c94eb57532ef3de55d28e5d23e3cd8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 4 Oct 2009 20:17:58 -0700 Subject: vary defaults for worker_connections Various concurrency models work and scale differently, pick counts that make a reasonable amount of sense... --- lib/rainbows.rb | 17 +++++++++++++---- lib/rainbows/http_server.rb | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3-24-ge0c7