A minimal, multi-threaded, Rack-compliant web server.
Start the server:
$ pill
Optionally, specify the port and number of maximum connections, like so:
$ pill -c 128 -p 4848
No surprises:
Pill web server (v0.5.1 codename Pak)
Maximum connections set to 128
Listening on 0.0.0.0:4848, CTRL+C to stop
Pill uses the Ruby standard socket
, stringio
, and thread
modules. A single process listens for incoming connections, with each acceptance assigned to a new thread:
loop do
connection, _ = @server.accept
Thread.new do
handler = Handler.new(connection, @app)
handler.read_request(1024 * 16)
end
end
A handler is instantiated for each connection to send the request for processing and to write back a response to the client socket when the parser callback is triggered:
def initialize(connection, app)
@connection = connection
@app = app
@parser = HTTP::Parser.new(self)
end
The handler object implements the callback functions to interface with the http/parser module, and defines a rack-compliant environment hash holding the body of the client request.
A minimal builder class is specified to operate on the config.ru
file in a Rack-based application, in order to allow for the inclusion of middleware in applications run on Pill.
Instead of instantiating threads per connection on the fly, the following are models that can be implemented for efficiency:
- Thread Pool
- Processes
- Preforking
- Evented
- Hybrids
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request