This project is still in a very early development stage. IT IS NOT READY FOR PRODUCTION!
Rhebok is High Performance Rack Handler/Web Server. 2x performance when compared against Unicorn.
Rhebok supports following features.
- ultra fast HTTP processing using picohttpparser
- uses accept4(2) if OS support
- uses writev(2) for output responses
- prefork and graceful shutdown using prefork_engine
- hot deploy and unix domain socket using start_server
- only supports HTTP/1.0. But does not support Keepalive.
This server is suitable for running HTTP application servers behind a reverse proxy like nginx.
Add this line to your application's Gemfile:
gem 'rhebok'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rhebok
$ rackup -s Rhebok -O Port=8080 -O MaxWorkers=10 -O MaxRequestPerChild=1000 -E production config.ru
nginx.conf
http {
upstream app {
server unix:/path/to/app.sock;
}
server {
location / {
proxy_pass http://app;
}
location ~ ^/(stylesheets|images)/ {
root /path/to/webapp/public;
}
}
}
command line of running Rhebok
$ start_server --path /path/to/app.sock --backlog 16384 -- rackup -s Rhebok \
-O MaxWorkers=10 -O MaxRequestPerChild=1000 -E production config.ru
hostname or ip address to bind (default: 0.0.0.0)
port to bind (default: 9292)
number of worker processes (default: 10)
max. number of requests to be handled before a worker process exits (default: 1000)
If set to 0
. worker never exists. This option looks like Apache's MaxRequestPerChild
if set, randomizes the number of requests handled by a single worker process between the value and that supplied by MaxRequestPerChlid (default: none)
seconds until timeout (default: 300)
if set, worker processes will not be spawned more than once than every given seconds. Also, when SIGHUP is being received, no more than one worker processes will be collected every given seconds. This feature is useful for doing a "slow-restart". See http://blog.kazuhooku.com/2011/04/web-serverstarter-parallelprefork.html for more information. (default: none)
Rhebok and Unicorn "Hello World" Benchmark (behind nginx reverse proxy)
ruby version
$ ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
nginx.conf
worker_processes 16;
events {
worker_connections 50000;
}
http {
include mime.types;
access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
etag off;
upstream app {
server unix:/dev/shm/app.sock;
}
server {
location / {
proxy_pass http://app;
}
}
}
config.ru
class HelloApp
def call(env)
[
200,
{ 'Content-Type' => 'text/html' },
['hello world ']
]
end
end
run HelloApp.new
command to run
$ start_server --path /path/to/app.sock -- rackup -s Rhebok \
-O MaxWorkers=8 -O MaxRequestPerChild=1000000 -E production config.ru
result
$ ./wrk -t 4 -c 500 -d 30 http://localhost/
Running 30s test @ http://localhost/
4 threads and 500 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.85ms 2.94ms 816.72ms 99.24%
Req/Sec 70.14k 9.13k 110.33k 76.74%
7885663 requests in 30.00s, 1.29GB read
Requests/sec: 262864.06
Transfer/sec: 44.11MB
unicorn.rb
$ cat unicorn.rb
worker_processes 8
preload_app true
listen "/dev/shm/app.sock"
command to run
$ unicorn -E production -c unicorn.rb config.ru
result
$ ./wrk -t 4 -c 500 -d 30 http://localhost/
Running 30s test @ http://localhost/
4 threads and 500 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 3.57ms 0.95ms 206.42ms 94.66%
Req/Sec 35.62k 3.79k 56.69k 77.38%
4122935 requests in 30.00s, 754.74MB read
Socket errors: connect 0, read 0, write 0, timeout 47
Requests/sec: 137435.52
Transfer/sec: 25.16MB
I used EC2 for benchmarking. Instance type if c3.8xlarge(32cores). A benchmark tool and web servers were executed at same hosts.
Gazelle Rhebok is created based on Gazelle code
Server::Stater a superdaemon for hot-deploying server programs
picohttpparser fast http parser
Copyright (C) Masahiro Nagano.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
- Fork it ( https://github.com/kazeburo/rhebok/fork )
- 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 a new Pull Request