Puma is a simple, fast, and highly concurrent HTTP 1.1 server for Ruby web applications. It can be used with any application that supports Rack, and is considered the replacement for Webrick and Mongrel. It was designed to be the go-to server for Rubinius, but also works well with JRuby and MRI.
Puma is intended for use in both development and production environments. Under the hood, Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way.
Puma then serves the request in a thread from an internal thread pool (which you can control). This allows Puma to provide real concurrency for your web application! With Rubinius 2.0, Puma will utilize all cores on your CPU with real threads, meaning you won’t have to spawn multiple processes to increase throughput. You can expect to see a similar benefit from JRuby.
On MRI, there is a Global Interpreter Lock (GIL) that ensures only one thread can be run at a time. But if you’re doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI’s throughput by allowing blocking IO to be run concurrently (EventMachine-based servers such as Thin turn off this ability, requiring you to use special libraries). Your mileage may vary. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like Rubinius or JRuby.
First, make sure Puma is in your Gemfile :
[code language="ruby"] gem 'puma' [/code]
Then start your server with the rails command :
[code language="ruby"] $ rails s Puma [/code]
To make Puma the default, paste this code into script/rails above require ‘rails/commands’ :
[code language="ruby"] require 'rack/handler' Rack::Handler::WEBrick = Rack::Handler.get(:puma) [/code]
Puma is the default server now if you use rails :
[code language="ruby"] rails s => Booting Puma => Rails 3.2.12 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Connecting to database specified by database.yml Puma 1.6.3 starting...* Min threads: 0, max threads: 16 * Environment: development * Listening on tcp://0.0.0.0:3000* [/code]