ngx_mruby - A Fast and Memory-Efficient Web Server Extension Mechanism Using Scripting Language mruby for nginx
C Ruby C++ Yacc Shell Nginx Other
Latest commit cc86a3d Apr 27, 2017 @matsumotory committed on GitHub Merge pull request #286 from yyamano/build-deps
Improve build dependencies
Permalink
Failed to load latest commit information.
dependence/ngx_devel_kit Merge commit '5e90183f9649bdce1ebc97975e4c9bbedf4630a2' as 'dependenc… Oct 13, 2015
docker Update mruby Jun 25, 2014
example Add compatible hello world code between ngx_mruby and mod_mruby Mar 1, 2014
misc fix usage of Dockerfile.travis_emulate Jun 3, 2016
mrbgems use fullchain certificate on auto-ssl Apr 23, 2017
mruby Merge commit '52b92527cdf99c07de234df6e6d48ca5256a4591' into mruby Apr 24, 2017
src Bump up version 1.19.4 Apr 14, 2017
test Workaround for iij/mruby-io#75 Apr 25, 2017
.clang-format Revert "Header line ignores clang-format" Feb 13, 2017
.gitignore Ignore emacs backup file. Apr 27, 2017
.gitmodules Don't use submodule Oct 13, 2015
.travis.yml remove older `MINOR` mainlines from travis.yml Apr 26, 2017
AUTHORS Add me? Dec 24, 2016
Dockerfile Rename matsumoto-r to matsumotory (GitHub Account) Dec 16, 2016
LEGAL Add LEGAL file Jul 26, 2013
MITL Update License information Apr 29, 2014
Makefile.in Make this work without BUILD_DYNAMIC_MODULE again. Apr 27, 2017
README.md Rename matsumoto-r to matsumotory (GitHub Account) Dec 16, 2016
TODO Update README Apr 30, 2014
apply-clang-format Add tool which apply clang-format to all code Nov 2, 2015
build.sh Improve build dependencies. Apr 27, 2017
build_config.rb Add Nginx::SSL::ACME class Mar 22, 2017
config.in Apply customized include directory and library directory if they are … Oct 13, 2016
configure Regenerate configure by autoconf Oct 13, 2016
configure.in Generate config from config.in Oct 13, 2016
nginx_version Just update nginx to v1.11.13 Apr 7, 2017
test.sh Improve build dependencies. Apr 27, 2017
update-mruby-subtree Refactor build system. Dec 7, 2016

README.md

Welcome to ngx_mruby Pages

Gitter Build Status wercker status

ngx_mruby mod_mruby performance

hello world simple benchmark, see details of blog entry.

Documents

What's ngx_mruby

ngx_mruby is A Fast and Memory-Efficient TCP/UDP Load Balancing and Web Server Extension Mechanism Using Scripting Language mruby for nginx.

  • ngx_mruby is to provide an alternative to lua-nginx-module or mod_mruby of Apache httpd.
  • Unified Ruby Code between Apache(mod_mruby), nginx(ngx_mruby) and other Web server software(plan) for Web server extensions.
  • You can implement nginx modules by Ruby scripts on nginx!
  • You can implement some Web server software extensions by same Ruby code (as possible)
  • Supported nginx 1.4/1.6/1.8./1.9./1.10./1.11.*
  • Benchmark between ngx_mruby and lua-nginx-module
# location /proxy {
#   mruby_set $backend "/path/to/proxy.rb";
#   proxy_pass   http://$backend;
# }

backends = [
  "test1",
  "test2",
  "test3",
]

r = Redis.new "192.168.12.251", 6379
r.get backends[rand(backends.length)]
  • see examples
  • Sample of Unified Ruby Code between Apache(mod_mruby) and nginx(ngx_mruby) for Web server extensions
  • You can implement some Web server software extensions by same Ruby code (as possible)
# Unified Ruby Code between Apache(mod_mruby) and nginx(ngx_mruby)
# for Web server extensions.
#
# Apache httpd.conf by mod_mruby
#
# <Location /mruby>
#     mrubyHandlerMiddle "/path/to/unified_hello.rb"
# </Location>
#
# nginx ngxin.conf by ngx_mruby
#
# location /mruby {
#     mruby_content_handler "/path/to/unified_hello.rb";
# }
#

Server = get_server_class

Server::rputs "Hello #{Server::module_name}/#{Server::module_version} world!"
# mod_mruby => "Hello mod_mruby/0.9.3 world!"
# ngx_mruby => "Hello ngx_mruby/0.0.1 world!"

Abstract

As the increase of large-scale and complex Web services, not only the development of Web applications is required, but also the implementation of Web server extensions in many cases. Most Web server extensions are mainly implemented in the C language because of fast and memory-efficient behavior, but by writing extensions using a scripting language we can achieve better maintainability and productivity.

However, if the existing methods are primarily intended to enhance not the implementation of Web applications but the implementation of internal processing of the Web server, the problem remains in terms of speed, memory-efficiency and safety.

Therefore, we propose a fast and memory-efficient Web server extension mechanism using a scripting language. We designed an architecture where the server process creates a region in memory to save the state of the interpreter at the server process startup, and multiple scripts share this region to process the scripts quickly when new request are made.

The server process frees the global variables table, the exception flag and the byte-code which cause an increase of memory usage, in order to reduce the memory usage and extend safety by preventing interference between each script because of sharing the region. We implemented a mechanism that can extend the internal processing of nginx easily by Ruby scripts using nginx and the embeddable scripting language mruby. It's called "ngx_mruby".

License

This project is under the MIT License: