David Heinemeier Hansson wrote:
I'm not sure I understand the question. You can start FCGIs any way
you want. The spawner is just a shortcut for starting many FCGIs at
once and the spinner is a insurance against fallen FCGIs. How does
either have any effect on RAM or start-up time?
The spinner process is running all the time, and because it has loaded
and initialized the whole Rails environment (boot.rb etc.) it uses a lot
of RAM. The same goes for the spawner process. It is started every
#{interval} seconds, and because it loads the Rails environment every
time - this can put a considerable load on a small server. IMO neither
spinner nor spawner do really need the Rails environment, all they do is
to call external scripts.
If you're in an environment where the RAM usage of 1 spinner is a
concern, then you probably don't need/want the functionality of the
spinner anyway. The spawner is triggered by the spinner, so if you
just use it on its own, then it only uses the RAM for a few seconds
until all the spinners are started.
It's the other way round. The spinner creates a new spawner process
every #{interval = 5} seconds. Starting the spawner is rather expensive
if it's done in a 5-second interval.
But hey, if you can make a silky clean refactoring that makes the
scripts not require the environment startup, but still use stubs like
all the others, then I'm all game for applying!
I can't think of an elegent way to do this right now, but attached is a
small patch that moves the spinner functionality into the spawner.
---
/opt/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/process/spawner.rb
Mon Dec 26 02:03:28 2005
+++ spawner.rb Tue Jan 10 04:59:25 2006
@@ -1,16 +1,21 @@
require 'optparse'
def spawn(port)
- print "Starting FCGI on port: #{port}\n "
+ puts "Starting FCGI on port: #{port}"
system("#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port}")
end
+def spawn_all
+ OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) }
+end
+
OPTIONS = {
:environment => "production",
:spawner => '/usr/bin/env spawn-fcgi',
:dispatcher => File.expand_path(RAILS_ROOT + '/public/dispatch.fcgi'),
:port => 8000,
- :instances => 3
+ :instances => 3,
+ :repeat => nil
}
ARGV.options do |opts|
@@ -37,6 +42,7 @@
opts.on("-p", "--port=number", Integer, "Starting port number (default:
#{OPTIONS[:port]})") { |OPTIONS[:port]| }
opts.on("-i", "--instances=number", Integer, "Number of instances (default:
#{OPTIONS[:instances]})") { |OPTIONS[:instances]| }
+ opts.on("-r", "--repeat=seconds", Integer, "Repeat spawn attempts every n
seconds (default: off)") { |OPTIONS[:repeat]| }
opts.on("-e", "--environment=name", String, "test|development|production
(default: #{OPTIONS[:environment]})") { |OPTIONS[:environment]| }
opts.on("-s", "--spawner=path", String, "default: #{OPTIONS[:spawner]}")
{ |OPTIONS[:spawner]| }
opts.on("-d", "--dispatcher=path", String, "default:
#{OPTIONS[:dispatcher]}") { |dispatcher| OPTIONS[:dispatcher] =
File.expand_path(dispatcher) }
@@ -49,4 +55,13 @@
end
ENV["RAILS_ENV"] = OPTIONS[:environment]
-OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) }
\ No newline at end of file
+
+if OPTIONS[:repeat]
+ loop do
+ spawn_all
+ puts "Sleeping for #{OPTIONS[:repeat]} seconds"
+ sleep OPTIONS[:repeat]
+ end
+else
+ spawn_all
+end
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core