Skip to content
This repository

Celluloid::IO-powered web server

Fetching latest commit…

Cannot retrieve the latest commit at this time


Build Status Dependency Status Code Climate

Reel is a fast, non-blocking "evented" web server built on http_parser.rb, websocket_parser, Celluloid::IO, and nio4r. Thanks to Celluloid, Reel also works great for multithreaded applications and provides traditional multithreaded blocking I/O support too.

Connections to Reel can be either non-blocking and handled entirely within the Reel::Server thread, or the same connections can be dispatched to worker threads where they will perform ordinary blocking IO. Reel provides no built-in thread pool, however you can build one yourself using Celluloid.pool, or because Celluloid already pools threads to begin with, you can simply use an actor per connection.

This gives you the best of both worlds: non-blocking I/O for when you're primarily I/O bound, and threads for where you're compute bound.

Is it any good?


Here's a "hello world" web server benchmark, run on a 2GHz i7 (OS X 10.7.3). All servers used in a single-threaded mode.

Reel performance on various Ruby VMs:

# httperf --num-conns=50 --num-calls=1000

Ruby Version        Throughput    Latency
------------        ----------    -------
JRuby 1.7.0         3978 req/s    (0.3 ms/req)
rbx HEAD            2288 reqs/s   (0.4 ms/req)
Ruby 1.9.3          2071 req/s    (0.5 ms/req)

Comparison with other web servers:

Web Server          Throughput    Latency
----------          ----------    -------
Goliath (0.9.4)     2058 reqs/s   (0.5 ms/req)
Thin    (1.2.11)    7502 reqs/s   (0.1 ms/req)
Node.js (0.6.5)     11735 reqs/s  (0.1 ms/req)

All Ruby benchmarks done on Ruby 1.9.3. Latencies given are average-per-request and are not amortized across all concurrent requests.


Reel also provides a "bare metal" API which was used in the benchmarks above. Here are some examples:

Block Form

Reel lets you pass a block to initialize which receives connections:

require 'reel'

Reel::Server.supervise("", 3000) do |connection|
  while request = connection.request
    case request
    when Reel::Request
      puts "Client requested: #{request.method} #{request.url}"
      request.respond :ok, "Hello, world!"
    when Reel::WebSocket
      puts "Client made a WebSocket request to: #{request.url}"
      request << "Hello everyone out there in WebSocket land"

When we read a request from the incoming connection, we'll either get back a Reel::Request object, indicating a normal HTTP connection, or a Reel::WebSocket object for WebSockets connections.

Subclass Form

You can also subclass Reel, which allows additional customizations:

require 'reel'

class MyServer < Reel::Server
  def initialize(host = "", port = 3000)
    super(host, port, &method(:on_connection))

  def on_connection(connection)
    while request = connection.request
      case request
      when Reel::Request
      when Reel::WebSocket

  def handle_request(request)
    request.respond :ok, "Hello, world!"

  def handle_websocket(sock)
    sock << "Hello everyone out there in WebSocket land!"

Framework Adapters


Reel can be used as a standard Rack server via the "reel" command line application. Please be aware that Rack support is experimental and that there are potential complications between using large numbers of rack middlewares and the limited 4kB stack depth of Ruby Fibers, which are used extensively by Celluloid. In addition, the Rack specification mandates that request bodies are rewindable, which prevents streaming request bodies as the spec dictates they must be written to disk.

To really leverage Reel's capabilities, you must use Reel via its own API, or another Ruby library with direct Reel support.


The most notable library with native Reel support is webmachine-ruby, an advanced HTTP framework for Ruby with a complete state machine for proper processing of HTTP/1.1 requests. Together with Reel, Webmachine provides full streaming support for both requests and responses.

To use Reel with Webmachine, add the following to your Gemfile:

gem 'webmachine', git: 'git://'

Then use config.adapter = :Reel when configuring a Webmachine app, e.g:

MyApp = do |app|
  app.routes do
    add ['*'], MyHome

  app.configure do |config|
    config.ip      = MYAPP_IP
    config.port    = MYAPP_PORT
    config.adapter = :Reel

See the Webmachine documentation for further information


  • Fork this repository on github
  • Make your changes and send me a pull request
  • If I like them I'll merge them
  • If I've accepted a patch, feel free to ask for commit access


Copyright (c) 2012 Tony Arcieri. Distributed under the MIT License. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.