Gary Haran.com


Rails Development With The Thin Web Server

Posted in Uncategorized by gary.haran on the February 21st, 2008

Thin is all about speed, security, stability and extensibility. If you haven’t seen the Thin Web Server benchmarks perhaps you should but that’s just good for pissing contests. True class is when you can package it all for better development as well.

One would think that because thin is so good with the stated goals that it would fall short when it comes to flexibility.

If you think that, you’d be wrong. After just a day running Thin in development mode I’m never using script/server again. I’m addicted to thin and I don’t mean in the anorexic way. This server can do gymnastics and lift heavy weights. It’s so easy to setup and use that you can expect lots of people to adopt it.

Want to learn more? Yes! Well let’s get started then!

Installing and Using Thin Web Server

$ sudo gem install thin

That’s it! You’ve just installed thin!

Starting thin instead of mongrel

In the root of your rails application:

$ thin start

This replaces script/server. Restarting is as easy as:

$ thin restart

Or if you want to stop Thin:

$ thin stop

And the good news is that you can do that from any console!

That’s pretty much vanilla flavor and by default it doesn’t spit out the logs to the console so you get extra speed right from the get go. But what if you want to see the logs?

Run Thin And Logs In A Single Console

$ thin start -d
$ tail -f log/development

Of course you can always run tail -f log/development in another tab or console. It’s all up to you! That’s what I call flexibility!

Advanced Development Options

I rely a lot on the front end tools such as Firebug to determine what’s being sent in Ajax calls but lately I had to determine what was being sent to and from a Flash Uploader.

There are some firefox plugins that exist that tell you what’s going on in http headers and what’s being sent. Unfortunately when you have 3 different version of Firefox installed in virtual machines it’s time consuming to install it everywhere. This is where the tracing option comes in handy in thin.

$ thin start -V

Now when you send a request you get the content of files displayed in your console and the status code that look like the following:

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 26999
Connection: close
Server: thin 0.6.4 codename Sexy Lobster

<!DOCTYPE html PUBLIC...

Of course piping all text through your console should only be used when you absolutely need to see the messages going back and forth so only use it when you want less speed in favor of more information. It’s all about flexibility!

Leave a Reply