1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
A Ruby/Rack web server built for parallelism
Find a file
2012-01-08 16:55:57 -03:00
bin Add ability to wakeup and cancel persistent connections 2011-12-08 12:17:45 -08:00
examples Add ability to use a config file (-C, --config) 2011-12-06 14:57:37 -08:00
ext/puma_http11 Build extensions 2012-01-08 16:32:32 -03:00
lib Remove non-required dirs from $LOAD_PATH 2012-01-08 16:48:51 -03:00
test Exclude UNIXSocket tests under Windows 2012-01-08 16:55:57 -03:00
tools minor test cleanups 2007-10-21 02:54:53 +00:00
.gitignore Ignore rubinius compiled files. 2010-04-28 20:30:21 -03:00
.travis.yml Fix race conditions in tests, change travis rbx name 2011-11-22 16:32:35 -08:00
COPYING Ruby license applied to all files 2006-06-30 20:42:12 +00:00
Gemfile Add rdoc and rake-compiler as gems 2011-10-22 23:17:29 -07:00
History.txt That was too early, revert to 1.2.0.beta.1 instead. 2010-07-24 14:04:12 -03:00
LICENSE Update license 2011-09-23 20:27:54 -07:00
Manifest.txt Fix manifest and gemspec 2011-12-19 13:55:32 -08:00
puma.gemspec Version bump 2011-12-19 14:18:27 -08:00
Rakefile Remove old Rakefile 2012-01-08 16:42:19 -03:00
README.md Fix extension typo 2012-01-06 11:10:51 -08:00
TODO oops... gems is quite necessary 2007-11-01 06:14:56 +00:00

Puma: A Ruby Web Server Built For Concurrency

Description

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.

Quick Start

The easiest way to get started with Puma is to install it via RubyGems. You can do this easily:

$ gem install puma

Now you should have the puma command available in your PATH, so just do the following in the root folder of your Rack application:

$ puma app.ru

Advanced Setup

Sinatra

You can run your Sinatra application with Puma from the command line like this:

$ ruby app.rb -s Puma

Or you can configure your application to always use Puma:

require 'sinatra'
configure { set :server, :puma }

If you use Bundler, make sure you add Puma to your Gemfile (see below).

Rails

First, make sure Puma is in your Gemfile:

gem 'puma'

Then start your server with the rails command:

$ rails s puma

Rackup

You can pass it as an option to rackup:

$ rackup -s puma

Alternatively, you can modify your config.ru to choose Puma by default, by adding the following as the first line:

#\ -s puma

Configuration

Puma provides numerous options for controlling the operation of the server. Consult puma -h (or puma --help) for a full list.

Thread Pool

Puma utilizes a dynamic thread pool which you can modify. You can set the minimum and maximum number of threads that are available in the pool with the -t (or --threads) flag:

$ puma -t 8:32

Puma will automatically scale the number of threads based on how much traffic is present. The current default is 0:16. Feel free to experiment, but be careful not to set the number of maximum threads to a very large number, as you may exhaust resources on the system (or hit resource limits).

Binding TCP / Sockets

In contrast to many server configs, Puma simply uses takes one URI parameter with the -b (or --bind) flag:

$ puma -b tcp://127.0.0.1:9292

Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)? No problem!

$ puma -b unix:///var/run/puma.sock

License

Puma is copyright 2011 Evan Phoenix and contributors. It is licensed under the BSD license. See the include LICENSE file for details.