mod_mruby - A Fast and Memory-Efficient Web Server Extension Mechanism Using Scripting Language mruby for Apache httpd
C Ruby Yacc C++ JavaScript Shell Other
Failed to load latest commit information.
docker Update docker example Jun 15, 2014
example Add example Apr 6, 2014
images Add image Apr 30, 2014
lib remove redis Dec 16, 2012
mrbgems Add @kentaro to spec author of mruby-rack-based-api #67 Sep 15, 2015
mruby Merge commit '2acfa66d12a66cbc2f2ab01fd6c01362cc3fd299' Feb 1, 2016
mruby_test Merge commit '253323eb647ae269ddc2eefdb16b86e30aa0008e' Feb 1, 2016
src Bump up version 1.13.11 Apr 18, 2016
test Add more tests taken from ngx_mruby Sep 15, 2015
webif Fix merge method error Mar 13, 2014
.clang-format Change ColumnLimit in clang-format Oct 5, 2015
.gitignore Update gitignore Jun 18, 2014
.gitmodules Remove submodules Oct 13, 2015
.travis.yml Update httpd version for travis Jul 29, 2016
AUTHORS AUTHORS created. Jul 6, 2012
Dockerfile Merge branch 'master' of github.com:matsumoto-r/mod_mruby Aug 17, 2014
LEGAL Update LICENSE information Apr 29, 2014
MITL Update LICENSE information Apr 29, 2014
Makefile.in Add mruby_test dir Sep 28, 2015
Makefile.w32 Specify absolute path for apxs. Jan 22, 2013
README.md Added Gitter badge Dec 16, 2014
TODO Add TODO May 26, 2014
apply-clang-format Add apply-clang-format tool Oct 5, 2015
build.sh Fix bug; related to matsumoto-r/ngx_mruby#116 May 4, 2015
build_config.rb Update build_config.rb Mar 31, 2016
config.h.in Fix HAVE_UNISTD_H warning and error log priority. Jan 22, 2013
configure Fix rake search path. Jul 6, 2015
configure.in Fix rake search path. Jul 6, 2015
httpd_version Update httpd version for travis Jul 29, 2016
test.sh Check the existing mruby_test submodule Sep 28, 2015
update-mruby-subtree Add mruby subtree tool Feb 1, 2016
wercker.yml Basic wercker.yml Oct 24, 2014

README.md

Welcome to mod_mruby Pages

Gitter Build Status wercker status

ngx_mruby mod_mruby performance

hello world simple benchmark, see details of blog entry.

Documents

What's mod_mruby

mod_murby is A Fast and Memory-Efficient Web Server Extension Mechanism Using Scripting Language mruby for 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 Apache modules by Ruby on Apache httpd.
  • You can implement some Web server software extensions by same Ruby code (as possible)
  • mod_mruby is to provide an alternative to mod_lua or ngx_mruby of nginx.
  • Supported Apache Version: 2.2 2.4
  • Supported Apache MPM: worker prefork event
  • Supported OS: Linux FreeBSD Windows and so on.
# Apache httpd.conf
# mrubyTranslateNameMiddle "/path/to/proxy.rb"
#

backends = [
  "http://192.168.0.101:8888/",
  "http://192.168.0.102:8888/",
  "http://192.168.0.103:8888/",
  "http://192.168.0.104:8888/",
]

# write balancing algorithm here.

r = Apache::Request.new()

r.handler  = "proxy-server"
r.proxyreq = Apache::PROXYREQ_REVERSE
r.filename = "proxy:" + backends[rand(backends.length)] + r.uri

Apache::return(Apache::OK)
  • see example
  • 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 a development of Web applications but also an implementation of Web server extensions is required in many cases. The Web server extensions were mainly implemented in C language because of fast and memory-efficient behavior, but extension methods using scripting language are proposed with consideration of maintainability and productivity. However, if the existing methods 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 fast, memory-efficiency and safety. Therefore, we propose a fast and memory-efficient Web server extension mechanism using scripting language. We design the architecture that a server process create the region to save the state of the interpreter at the server process startup, and multiple scripts share the region in order to process fast when the script is called as internal processing from a Web server process. The server process free the global variables table, the exception flag and the byte-code which cause the increase of memory usage mainly, in order to reduce the memory usage and extend safely by preventing interference between each scripts because of sharing the region. We implement the mechanism that can extend the internal processing of Apache easily by Ruby scripts using Apache and embeddable scripting language mruby. It's called "mod_mruby".

License

under the MIT License: