Clear, usable interfaces. Clean, accessible code.

Route 19

Logbook.

Lighttpd and Rails via Thin Feb. 25 at 10:49 am

I briefly experimented with running a server for Rails with Apache and Passenger (mod_rails), and it was certainly convenient by way of how few moving parts there were to manage, but I just prefer Lighttpd and was annoyed by Passenger’s delay on an initial load.

Instead I’m running a single Thin server for each low-traffic Rails site, proxied behind Lighttpd. Each Thin server uses about 50 Mb of memory on my 64 bit Ubuntu setup. The Rails logs are consistently reporting 4 or 8 ms processing times, which is the same as with Passenger except passenger would often have 40 or 50 ms processing times for a fresh process start.

A simple test with Apache Bench locally (ab -n 10000 -c 100 http://…) showed Thin at 70 requests/sec after configuring Lighttpd to handle the static files (images, stylesheets, javascripts, etcetera) directly instead of passing them on to Thin.

Lighttpd.conf with mod_proxy enabled:

$HTTP["host"] "website.tld" { $HTTP["url"] =~ "^/((images|stylesheets|javascripts|assets)/(.*)$|(favicon\.ico|robots\.txt))" { server.document-root = "/path/to/rails/root/public/" } else $HTTP["host"] "website.tld" { proxy.balance = "fair" proxy.server = ("" => ( ( "host" => "127.0.0.1", "port" => 3000 ) # room for more instances ) ) } }

Thin configuration for this app is included in my rails config directory and symlinked to /etc/thin/railsappname.yml:

# sudo thin config -C /etc/thin/railsappname.yml -c /path/to/rails/root/ --servers 1 -e production --- pid: tmp/pids/thin.pid log: log/thin.log port: 3000 timeout: 30 max_conns: 1024 chdir: /path/to/rails/root/ max_persistent_conns: 512 environment: production address: 0.0.0.0 servers: 1 require: [] daemonize: true

For bonus points, here’s a Capistrano deploy.rb addition for controlling Thin:

namespace :deploy do %w(start stop restart).each do |action| desc "#{action} this app's Thin Cluster" task action.to_sym, :roles => :app do run "/etc/init.d/thin #{action} -C /etc/thin/#{application}.yml" end end end

UPDATE:

I’m currently testing out Apache2+Passenger again on a Linode 360 VPS (32 bit Ubuntu) and I’ve been very pleased with the results so far. Seriously considering a jump from Lighttpd+PHP+Thin to Apache2+PHP+Passenger. If only there was a Passenger-type solution for Lighttpd I’d never consider Apache, but it’s not as bad as I remember it (1.3).

Recent Entries

More