"A dizzying lifetime... reeling by on celluloid" -- Rush / Between The Wheels

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 (handling HTTP, HTTPS, or UNIX sockets),
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.

Framework Adapters

Rack

Webmachine

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://github.com/seancribbs/webmachine-ruby.git'

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

Ruby API

Reel aims to provide a "bare metal" API that other frameworks (such as Rack
and Webmachine) can leverage. This API can also be nice in performance critical
applications.

Block Form

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

require'reel'Reel::Server::HTTP.supervise("0.0.0.0",3000)do|connection|# Support multiple keep-alive requests per connection
connection.each_requestdo|request|# WebSocket support
ifrequest.websocket?puts"Client made a WebSocket request to: #{request.url}"websocket=request.websocketwebsocket<<"Hello everyone out there in WebSocket land"websocket.closeelseputs"Client requested: #{request.method}#{request.url}"request.respond:ok,"Hello, world!"endendendsleep

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'classMyServer<Reel::Server::HTTPdefinitialize(host="127.0.0.1",port=3000)super(host,port,&method(:on_connection))enddefon_connection(connection)connection.each_requestdo|request|ifrequest.websocket?handle_websocket(request.websocket)elsehandle_request(request)endendenddefhandle_request(request)request.respond:ok,"Hello, world!"enddefhandle_websocket(sock)sock<<"Hello everyone out there in WebSocket land!"sock.closeendendMyServer.run

Contributing

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

License

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