• Stars
    star
    240
  • Rank 168,229 (Top 4 %)
  • Language
    C
  • License
    Other
  • Created almost 10 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

High Performance Preforked Rack Handler

Rhebok

rhebok logo

Build Status

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 using start_server (here is golang version by lestrrat-san)
  • supports HTTP/1.1 except for KeepAlive
  • supports OobGC

This server is suitable for running HTTP application servers behind a reverse proxy like nginx.

Installation

Add this line to your application's Gemfile:

gem 'rhebok'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rhebok

Usage

$ rackup -s Rhebok --port 8080 -O MaxWorkers=5 -O MaxRequestPerChild=1000 -O OobGC=yes -E production config.ru

Sample configuration with Nginx

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

$ rackup -s Rhebok -O Path=/path/to/app.sock \
  -O MaxWorkers=5 -O MaxRequestPerChild=1000 -E production config.ru

Options

ConfigFile

filename to load options. For details, please read Config File section

Host

hostname or ip address to bind (default: 0.0.0.0)

Port

port to bind (default: 9292)

Path

path to listen using unix socket

BackLog

specifies a listen backlog parameter (default: Socket::SOMAXCONN. usually 128 on Linux )

ReusePort

enable SO_REUSEPORT for TCP socket

MaxWorkers

number of worker processes (default: 5)

MaxRequestPerChild

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

MinRequestPerChild

if set, randomizes the number of requests handled by a single worker process between the value and that supplied by MaxRequestPerChlid (default: none)

Timeout

seconds until timeout (default: 300)

OobGC

Boolean like string. If true, Rhebok execute GC after close client socket. (defualt: false)

MaxGCPerRequest

If gctools is available, this option is not used. invoke GC by GC::OOB.run after every requests.

Max number of request before invoking GC (defualt: 5)

MinGCPerRequest

If set, randomizes the number of request before invoking GC between the number of MaxGCPerRequest (defualt: none)

Chunked_Transfer

If set, use chunked transfer for response (default: false)

SpawnInterval

if set, worker processes will not be spawned more than once than every given seconds. Also, when SIGUSR1 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)

Config File

load options from specified config file. If same options are exists in command line and the config file, options written in the config file will take precedence.

$ cat rhebok_config.rb
host '127.0.0.1'
port 9292
max_workers ENV["WEB_CONCURRENCY"] || 3
before_fork {
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
}
after_fork {
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
}
$ rackup -s Rhebok -O ConfigFile=rhebok_config.rb -O port 8080 -O OobGC -E production
Rhebok starts Listening on 127.0.0.1:9292 Pid:11892

Supported options in config file are below.

host

port

path

backlog

reuseport

max_workers

timeout

max_request_per_child

min_request_per_child

oobgc

max_gc_per_request

min_gc_per_request

chunked_transfer

spawn_interval

before_fork

proc object. This block will be called by a master process before forking each worker

after_fork

proc object. This block will be called by a worker process after forking

Signal Handling

Master process

  • TERM, HUP: If the master process received TERM or HUP signal, Rhebok will shutdown gracefully
  • USR1: If set SpawnInterval, Rhebok will collect workers every given seconds and exit

worker process

  • TERM: If the worker process received TERM, exit after finishing current request

Benchmark

Rhebok and Unicorn "Hello World" Benchmark (behind nginx reverse proxy)

image

"nginx static file" represents req/sec when delivering 13 bytes static files from nginx

Application code is here.

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;
    }
  }
}

Rhebok

command to run

$ start_server --backlog=16384 --path /dev/shm/app.sock -- \
  bundle exec --keep-file-descriptors rackup -s Rhebok \
    -O MaxWorkers=8 -O MaxRequestPerChild=0 -E production config.ru

Hello World/Rack Application

$ ./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.74ms  661.27us  38.69ms   91.19%
    Req/Sec    72.69k     9.42k  114.33k    79.43%
  8206118 requests in 30.00s, 1.34GB read
Requests/sec: 273544.70
Transfer/sec:     45.90MB

Sinatra

$ ./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    16.39ms  418.08us  22.25ms   78.25%
    Req/Sec     7.73k   230.81     8.38k    70.81%
  912104 requests in 30.00s, 273.09MB read
Requests/sec:  30404.28
Transfer/sec:      9.10MB

Rails

$ ./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   101.13ms    2.57ms 139.04ms   96.88%
    Req/Sec     1.24k    27.11     1.29k    82.98%
  148169 requests in 30.00s, 178.18MB read
Requests/sec:   4938.93
Transfer/sec:      5.94MB

Unicorn

unicorn.rb

$ cat unicorn.rb
worker_processes 8
preload_app true
listen "/dev/shm/app.sock"

command to run

$ bundle exec unicorn -c unicorn.rb -E production config.ru

Hello World/Rack Application

$ ./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.50ms  518.60us  30.28ms   90.35%
    Req/Sec    37.99k     4.10k   56.56k    72.14%
  4294095 requests in 30.00s, 786.07MB read
Requests/sec: 143140.20
Transfer/sec:     26.20MB

Sinatra

$ ./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    19.31ms    1.09ms  65.92ms   89.94%
    Req/Sec     6.55k   312.92     7.24k    73.41%
  775712 requests in 30.00s, 244.09MB read
Requests/sec:  25857.85
Transfer/sec:      8.14MB

Rails

$ ./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   105.70ms    4.70ms 151.11ms   93.50%
    Req/Sec     1.19k    44.16     1.25k    89.13%
  141846 requests in 30.00s, 172.74MB read
Requests/sec:   4728.11
Transfer/sec:      5.76MB

Server Environment

I used EC2 for benchmarking. Instance type if c3.8xlarge(32cores). A benchmark tool and web servers were executed at same hosts. Before benchmark, increase somaxconn and nfiles.

See Also

Gazelle Rhebok is created based on Gazelle code

Server::Stater a superdaemon for hot-deploying server programs

picohttpparser fast http parser

LICENSE

Copyright (C) Masahiro Nagano.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Contributing

  1. Fork it ( https://github.com/kazeburo/rhebok/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

More Repositories

1

GrowthForecast

Lightning Fast Graphing/Visualization
Perl
233
star
2

cloudforecast

the server metrics gathering
Perl
149
star
3

chocon

chocon is a simple proxy server for persisting connections between upstream servers.
Go
142
star
4

mysetup

my setup scripts repository
Shell
134
star
5

Gazelle

Preforked Plack Handler for performance freaks
Perl
73
star
6

Kurado

monitor metrics
Perl
71
star
7

Monoceros

PSGI/Plack server with event driven connection manager, preforking workers
Perl
55
star
8

HRForecast

Perl
49
star
9

Proclet

minimalistic Supervisor
Perl
37
star
10

wsgate-server

a websocket to tcp proxy/bridge server
Go
36
star
11

Kossy

sinatra-ish simple waf
Perl
34
star
12

Plack-Middleware-ServerStatus-Lite

Plack-Middleware-ServerStatus-Lite
Perl
25
star
13

prefork_engine

a simple prefork server framework / ruby port of perl's Parallel::Prefork
Ruby
24
star
14

GreenBuckets

Perl
23
star
15

query-digester

pt-query-digest wrapper to make ops simple
Perl
23
star
16

Log-Minimal

Minimal Logger
Perl
23
star
17

pico_http_parser

Fast HTTP Parser using picohttpparser
Ruby
19
star
18

isucon2_hack

isucon2 hack
Perl
19
star
19

Redis-Jet

Yet another XS implemented Redis client
XS
18
star
20

custom-mackerel-plugins

my custom mackerel plugins
Perl
17
star
21

motarei

Simple tcp proxy for Docker Hot deploy
Go
17
star
22

go-jmx-get

tiny jmx client
Go
16
star
23

DBIx-Sunny

Perl
16
star
24

docker-h2o

Dockerfile for h2o HTTP Server with graceful restart support
Shell
12
star
25

Plack-Builder-Conditionals

Plack::Builder extension
Perl
11
star
26

Plack-Middleware-Expires

mod_expires for plack
Perl
11
star
27

wsgate-client

a websocket to tcp proxy/bridge client server
Go
10
star
28

Plack-Server-AnyEvent-Prefork

Prefork AnyEvent based HTTP Server
Perl
10
star
29

mackerel-plugin-axslog

Yet Another mackerel-plugin for analyzing and visualizing Acesslog
Go
10
star
30

mackerel-plugin-pinging

ICMP Ping RTT custom mackerel plugin
Go
9
star
31

Apache-LogFormat-Compiler

Compile LogFormat to perl-code
Perl
9
star
32

Cache-Memcached-IronPlate

Best practices for Cache::Memcached
Perl
9
star
33

Twiggy-Prefork

Preforking AnyEvent HTTP server for PSGI
Perl
9
star
34

myps

Like pgrep and pkill, grep MySQL processlist and kill threads.
Go
8
star
35

percentile

Go
8
star
36

sabo

bandwidth limiting pipe with collaborative capability
Go
8
star
37

Scope-Container

Perl
8
star
38

build_mysql_mroonga_rpm

build mysql_mroonga.rpm by Vagrant provisioners
Shell
8
star
39

JavaScript-Value-Escape

Perl
7
star
40

isucon3qualifier-myhack

Perl
7
star
41

ppdp

Proxy Protocol Dump Proxy
Go
7
star
42

Scope-Container-DBI

DB connection manager with Scope::Container
Perl
6
star
43

heroku-buildpack-perl-procfile

a Heroku buildpack that runs any perl applications from Procfile
6
star
44

Cookie-Baker

Cookie string generator
Perl
6
star
45

p5-Alien-RRDtool

Installation of RRDs.pm (Perl binding for RRDtool)
Perl
6
star
46

rpm

my rpm repository
6
star
47

NoNoPaste

yet another nopaste
Perl
6
star
48

mackerel-plugin-maxcpu

Go
6
star
49

jstat2gf

Perl
5
star
50

chunkview

chuncked trasnfer visualizer
Perl
5
star
51

Time-TZOffset

Show timezone offset strings like +0900
C
5
star
52

NoNoPaste-Cloud

dotcloud nonopaste
Perl
5
star
53

mysql40dump

mysqldump wrapper for MySQL 4.0
Perl
5
star
54

Plack-Middleware-DBIx-DisconnectAll

Disconnect all database connection at end of request
Perl
5
star
55

isucon5-elimination-public

Perl
5
star
56

POSIX-strftime-Compiler

Perl
5
star
57

HTTP-Entity-Parser

PSGI compliant HTTP Entity Parser
Perl
5
star
58

Plack-Middleware-Scope-Container

Perl
5
star
59

Data-Page-Navigation

adds methods for page navigation link to Data::Page
Perl
4
star
60

docker-perl-build

docker image of perl-build
Shell
4
star
61

Plack-App-PHPCGI

execute PHP script as CGI
Perl
4
star
62

http-dump-request

http-dump-request server and docker container for monitoring and tests
Go
4
star
63

mackerel-plugin-postfix-log

Read and analyze postfix logs
Go
4
star
64

vagrant-destroy-provisioner

vagrant-destroy-provisioner plugin allows a VM to be destroyed as a provisioning step.
Ruby
4
star
65

check_http2

Nagios check_http plugin alternative powered by Go
Go
3
star
66

isucon11-final

final isucasy XI
Vue
3
star
67

diff-detector

a tiny tool
Go
3
star
68

isucon_summer_class_2014

ISUCON 夏期講習 2014
Go
3
star
69

CoreListWeb

Module::CoreList Web
Perl
3
star
70

mssh

ssh tool
3
star
71

check-cert-net

Check a remote certification expiry using openssl s_client
Go
3
star
72

mackerel-plugin-log-counter

mackerel metric plugin for count lines in log
Go
3
star
73

Plack-Middleware-Log-Minimal

Perl
3
star
74

mod_copy_header

copy a response header to notes
C
3
star
75

wg-keygen-rep

wireguard keypair generator with salt string
Go
3
star
76

Module-Build-Pluggable-CPANfile

Include cpanfile
Perl
3
star
77

WWW-GoogleAnalytics-Mobile

PSGI Application of Google Analytics for Mobile and client
Perl
3
star
78

Cache-Isolator

Perl
3
star
79

check_memcached_val

nagios plugin for checking value in a memcached server
Perl
3
star
80

check-lastlog

Check users who have not logged in recently
Go
2
star
81

Redis-Tiny

deprecated
Perl
2
star
82

deteco

Simple auth server used JWT & public-key cryptography
Go
2
star
83

isucon5-final-public

Perl
2
star
84

isius

Ping/TCP/HTTP/HTTPS monitoring agent server
Go
2
star
85

mackerel-plugin-resolver-synthetic

mackerel plugin for monitoring dns server as linux resolver
Go
2
star
86

tanzak

たんざく
Perl
2
star
87

go-check-mysql-msr

check multi source replication
Go
2
star
88

connstorm

Go
2
star
89

App-derived

run command periodically and calculate rate and check from network
Perl
2
star
90

Cache-Memcached-Fast-Safe

Cache::Memcached::Fast with sanitizing keys and fork-safe
Perl
2
star
91

DBIx-DSN-Resolver

Resolv hostname within dsn string
Perl
2
star
92

limilic2

Perl
2
star
93

ltsvparser

LTSV (Labeled Tab-separated Values) parser for Go language
Go
2
star
94

private-isu-challenge

Go
2
star
95

Plack-Middleware-AxsLog

Alternative AccessLog Middleware
Perl
2
star
96

the-rp

the reverse HTTP an TCP Reverse proxy supports asynchronous upstream resolution and some balancing strategy
Go
2
star
97

File-RotateLogs

Rotate log file
Perl
2
star
98

relaxlogs

CLI for lestrrat-go/file-rotatelogs
Go
2
star
99

AnyEvent-DNS-Cache-Simple

provides simple cache for AnyEvent::DNS
Perl
2
star
100

Time-Crontab

Parser for crontab date and time field
Perl
2
star