concept Thin in category ruby

appears as: Thin
Ruby in Practice

This is an excerpt from Manning's book Ruby in Practice.

Ruby comes with a built-in web server called WEBrick, a simple and lightweight server that is an adequate choice for development and prototyping. For production, though, we recommend using Mongrel or Thin. Both are faster and more stable than WEBrick, and you can use them as standalone servers, or to deploy a cluster of load-balanced application servers behind Apache or Nginx.

Mongrel is a lightweight web server that incorporates a native library—C code on most platforms, and Java code when running on JRuby—to handle the CPU-intensive portion of HTTP processing, offering simple setup and configuration with real-world performance. Thin is another lightweight web server that uses the Mongrel HTTP processing library in combination with Event Machine, a high-performance I/O network library, offering better throughput and scalability.

Mongrel and Thin are both viable options, and while Thin has the edge on performance and scalability, Mongrel has been around for longer and has better tooling support and more extensive documentation.

It was difficult for us to choose one server to cover. Fortunately, they’re similar enough in principles and basic usage, so we decided to base our examples on Thin, and to highlight the differences in sidebars.

Although Thin and Mongrel are excellent choices for handling the dynamic portion of an application, and they support a variety of frameworks (Rails, Merb, Camping, to name but a few), they do not offer the same capabilities you would expect from a full-fledged web server. Neither one is a web server we would expose directly to the internet. Rather, we’re going to delegate that task to a more capable frontend web server, and configure it to reverse proxy into our Thin/Mongrel application servers. We’ll explain the basics of this architecture next.

C.3. Setting up Thin

True to its name, Thin is a light web server that’s incredibly easy to set up (visit http://code.macournoyer.com/thin/ for more information). We’re going to start from an existing Rails application and work our way to having an operating system service that manages multiple application instances.

If you don’t already have Thin, now is the time to install it by running gem install thin. We’ll be conservative and start out by testing a single instance of the application. From the root directory of your Rails application, issue the following command:

$ thin start -e production --stats /stats

After you start Thin, you should see some output about a server starting up and serving on port 3000. Thin is quick enough that you’ll want to use it in development instead of WEBrick, and it knows that, so it defaults to run in development mode.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest