Trusterd is a high performance HTTP/2 Web Server scripting with mruby using nghttp2 and mruby-http2. You can get HTTP/2 Web Server quickly which is high permance and customizable with mruby.
This is a very early version, please test and report errors. Wellcome pull-request.
- more customizable Web server configration
- Server Push
- nghttp2 Requirements
- mruby-http2 Requirements
- Trusterd Requirements
- libjemalloc-dev
- qrintf-gcc
- If you don't have jemalloc and qrintf-gcc, comment out these lines on build_config.rb
After reading .travis.yml, you might easy to understand the install
Please see qrintf-gcc
sudo apt-get install libjemalloc-dev
git clone https://github.com/matsumoto-r/trusterd.git
cd trusterd
make
make install INSTALL_PREFIX=/usr/local/trusterd
SERVER_NAME = "Trusterd"
SERVER_VERSION = "0.0.1"
SERVER_DESCRIPTION = "#{SERVER_NAME}/#{SERVER_VERSION}"
root_dir = "/usr/local/trusterd"
s = HTTP2::Server.new({
#
# required config
#
:port => 8080,
:document_root => "#{root_dir}/htdocs",
:server_name => SERVER_DESCRIPTION,
# support prefork only when linux kernel supports SO_REUSEPORT
# :worker => 4,
# required when tls option is true.
# tls option is true by default.
#:key => "#{root_dir}/ssl/server.key",
#:crt => "#{root_dir}/ssl/server.crt",
# listen ip address
# default value is 0.0.0.0
# :server_host => "127.0.0.1",
#
# optional config
#
# debug default: false
# :debug => true,
# tls default: true
:tls => false,
# damone default: false
# :daemon => true,
# callback default: false
# :callback => true,
# connection_record defualt: true
# :connection_record => false,
})
#
# when :callback option is true,
#
# s.set_map_to_strage_cb {
#
# p "callback bloack at set_map_to_strage_cb"
# p s.request.uri
# p s.request.filename
#
# # location setting
# if s.request.uri == "/index.html"
# s.request.filename = "#{root_dir}/htdocs/hoge"
# end
# p s.request.filename
#
# # you can use regexp if you link regexp mrbgem.
# # Or, you can use KVS like mruby-redis or mruby-
# # vedis and so on.
#
# # Experiment: reverse proxy config
# # reciev front end with HTTP/2 and proxy upstream server with HTTP/1
# # TODO: reciev/send headers transparently and support HTTP/2 at upstream
#
# if s.request.uri =~ /^\/upstream(\/.*)/
# s.upstream_uri = $1
# s.upstream = “http://127.0.0.1“
# end
#
# # dynamic content with mruby
# if s.request.filename =~ /^.*\.rb$/
# s.enable_mruby
# end
#
# # dynamic content with mruby sharing mrb_state
# if s.request.filename =~ /^.*\_shared.rb$/
# s.enable_shared_mruby
# end
#
#
# }
# s.set_content_cb {
# s.rputs "hello trusterd world from cb"
# s.echo "+ hello trusterd world from cb with \n"
# }
#
# f = File.open "#{root_dir}/logs/access.log", "a"
#
# s.set_logging_cb {
#
# p "callback block after send response"
# f.write "#{s.conn.client_ip} #{Time.now} - #{s.r.uri} - #{s.r.filename}\n"
#
# }
s.run
make start INSTALL_PREFIX=/usr/local/trusterd
or
$(INSTALL_PREFIX)/bin/trusterd $(INSTALL_PREFIX)/conf/trusterd.conf.rb
make clean
nghttp is a client tool for HTTP/2.
$ nghttp http://127.0.0.1:8080/index.html
hello trusterd world.
docker pull matsumotory/trusterd
docker run -d -p 8080:8080 matsumotory/trusterd
nghttp -v http://127.0.0.1:8080/index.html
docker build -t local/trusterd .
docker run -d -p 8080:8080 local/trusterd
nghttp -v http://127.0.0.1:8080/index.html
- Ubuntu14.04 on VMWare
- Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz 4core
- Memory 8GB
SERVER_NAME = "Trusterd"
SERVER_VERSION = "0.0.1"
SERVER_DESCRIPTION = "#{SERVER_NAME}/#{SERVER_VERSION}"
root_dir = "/usr/local/trusterd"
s = HTTP2::Server.new({
:port => 8081,
:document_root => "#{root_dir}/htdocs",
:server_name => SERVER_DESCRIPTION,
:tls => false,
})
s.run
h2load is a benchmark tool for HTTP/2.
HTTP/2
Server \ size of content | 6 bytes | 4,096 bytes |
---|---|---|
nghttpd (nghttpd @ ab1dd11) single process | 116,285 | 59,330 |
tiny-nghttpd (nghttpd @ ab1dd11) single process | 196,653 | 104,483 |
Trusterd @ 2432cc5 single process | 202,910 | 89,699 |
Trusterd @ 2432cc5 4 process prefork mode | 509,059 | h2load saturation |
H2O @ 3de8911 single process | 216,664 | 112,418 |
h2load -c 500 -m 100 -n 2000000
Ref: HTTP/1.1 on same benchmark environment
Server \ size of content | 6 bytes | 4,096 bytes |
---|---|---|
nginx single process | 21,708 | 22,366 |
nginx 4 process prefork mode | 67,349 | 56,203 |
weighttp -k -c 500 -n 200000
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 62085 0.0 0.0 46668 2288 pts/4 S+ 16:41 0:00 | \_ /usr/local/trusterd/bin/trusterd /usr/local/trusterd/conf/trusterd.conf.rb
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 62085 63.3 0.0 49200 5144 pts/4 S+ 16:41 0:47 | \_ /usr/local/trusterd/bin/trusterd /usr/local/trusterd/conf/trusterd.conf.rb
under the MIT License: