Changing to thin from mongrel

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 likethin -e production -s 6That’s 6 servers running on 0.0.0.0:3000 to 0.0.0.0:3005Look 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)  endend

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)  endend

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
Advertisements

2 thoughts on “Changing to thin from mongrel

  1. 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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s