Thin: A Ruby HTTP Daemon That’s Faster Than Mongrel
Thin is a new Web server / daemon written in Ruby by Marc-André Cournoyer that uses the EventMachine, Rack, and Mongrel libraries. EventMachine makes it super fast at processing network I/O, Rack makes it easy to integrate with existing Ruby Web app frameworks, and Mongrel helps it parse HTTP. So, yes, the title is slightly misleading. Thin actually relies on Mongrel, but is ultimately faster than it, even against Mongrel's EventMachine-enhanced guise.
You can get started with Thin with a simple sudo gem install thin and then you can use it with any Rack supporting Web app / framework. With a Rails app, for example, a simple thin start in the base directory will get things moving.
January 5, 2008 at 4:40 am
Here's a link to the home page: http://code.macournoyer.com/thin/
January 5, 2008 at 4:25 pm
For clarity: it uses only mongrel parser as we can read on Thin web "the root of Mongrel speed and security".
January 5, 2008 at 4:30 pm
Marc-André Cournoyer is a prolific contributor for the Rails community. I suggest everyone to start following him on his blog : http://macournoyer.wordpress.com
January 5, 2008 at 8:47 pm
Cool!
Here's a quick rake task to make a thin cluster:
rake thin:cluster:start
rake thin:cluster:stop
For the start task, you can pass in the RAILS_ENV and the SIZE of the cluster (default 4).
rake thin:cluster:start RAILS_ENV=production SIZE=10
namespace :thin do
namespace :cluster do
desc 'Start thin cluster'
task :start => :environment do
`cd #{RAILS_ROOT}`
port_range = RAILS_ENV == 'development' ? 3 : 8
(ENV['SIZE'] ? ENV['SIZE'].to_i : 4).times do |i|
Thread.new do
port = "#{port_range}%03d" % i
str = "thin start -d -p#{port} -Ptmp/pids/thin-#{port}.pid"
str += " -e#{RAILS_ENV}"
puts "Starting server on port #{port}..."
`#{str}`
end
end
end
desc 'Stop thin cluster'
task :stop => :environment do
`cd #{RAILS_ROOT}`
port_range = RAILS_ENV == 'development' ? 3 : 8
Dir.new("#{RAILS_ROOT}/tmp/pids").each do |file|
Thread.new do
if file.starts_with?("thin-#{port_range}")
str = "thin stop -Ptmp/pids/#{file}"
puts "Stopping server on port #{file[/\d+/]}..."
`#{str}`
end
end
end
end
end
end
January 5, 2008 at 10:36 pm
I swear I posted a comment yesterday!?
Thx a lot Peter for talking about my project.
Just to be clear, Thin doesn't depend on Mongrel. But the Thin parser is a fork of the excellent Mongrel parser, customize for greater performances with Rack.
January 6, 2008 at 2:48 pm
@macournoyer: how is the memory use with Thin (i.e. Thin taking up memory as time goes on)? Thanks.
January 6, 2008 at 10:09 pm
I create a new Rails project and run thin with:
rails depot
cd depot
thin start
Then I browse to http://localhost:3000 I get this rrouting error:
no route found to match "/" with {:method=>:get}
If I start mongrel:
script/server
I get the typical "Welcome Aboard" Rails page.
What's missing in my process to use thin for the webserver?
I may be back a rev on Rails fro example.
January 7, 2008 at 12:15 am
@Robert: Thin takes a little less memory then mongrel since it doesn't use threads.
@McD: yeah, that url rewriting part hasn't been implemented yet, it's on the TODO list though :) So page caching and the /index.html page won't work for now but the rest should.
January 7, 2008 at 5:49 pm
I hope the Ruby/Rails sharks don't cause Marc-André Cournoyer to become unemployed and homeless.
January 7, 2008 at 10:33 pm
Maybe this new competition will force *** back into mongrel development?
Pingback: Rails Magnet
January 23, 2008 at 11:23 pm
lol @ Derek... literally too, thanks for that :)