Changing to thin from mongrel
Categories rails, ruby | 13 March, 2008 | By Stephen Sykes
Thin is getting some attention, so I thought we would give it a try.
Installation is just a matter of gem install thin.
Run it with something like
thin -e production -s 6
That’s 6 servers running on 0.0.0.0:3000 to 0.0.0.0:3005
Look at the examples if you need to make a monit recipe.
One thing we have is some code to make individual log files for each server instance. This is how it was with mongrel – we put this code in environment.rb inside the Rails::Initializer block:
if ENV['RAILS_ENV'] == 'production'
if defined?(Mongrel::HttpServer)
ObjectSpace.each_object(Mongrel::HttpServer) {|i| @port = i.port}
@port = "unknown" unless @port && @port.to_i > 0
config.logger = Logger.new(File.expand_path(
RAILS_ROOT+"/log/#{ENV['RAILS_ENV']}.#{@port}.log"), 2, 25000000)
end
end
Somthing very similar will work with thin:
if ENV['RAILS_ENV'] == 'production'
if defined?(Thin::Server)
ObjectSpace.each_object(Thin::Server) {|i| @port = i.backend.port}
@port = "unknown" unless @port && @port.to_i > 0
config.logger = Logger.new(File.expand_path(
RAILS_ROOT+"/log/#{ENV['RAILS_ENV']}.#{@port}.log"), 2, 25000000)
end
end
With this code in place you will get individual log files named production.3000.log, production.3001.log etc.
Finally we were seeing these errors:
terminate called after throwing an instance of 'std::runtime_error' what(): unable to delete epoll event: Bad file descriptor
This is a known problem not with thin, but with EventMachine. Grab an updated gem like this:
gem install eventmachine --source http://code.macournoyer.com
RSS
Hey Stephen,
thx for the post on Thin.
There’s a better warning message to prevent “Bad file descriptor” in latest version.
Let me know if you have any problem using thin!
It’s going very well so far, thanks for a lovely piece of software!