I hope that title excited you as much as it did when I figured out the
awesome connection between LuaJIT's FFI and libCling's JIT to compile and
share symbols on the fly.
*What am I talking about?
*
The Cling project. <http://root.cern.ch/drupal/content/cling>
> Cling is an interactive C++ interpreter, built on the top of LLVM and
> Clang libraries. Its advantages over the standard interpreters are that it
> has command line prompt and uses just-in-time (JIT) compiler for
> compilation. Many of the developers (e.g. Mono in their project called
> CSharpRepl <http://www.mono-project.com/CsharpRepl>) of such kind of
> software applications name them interactive compilers.
>
*What does this have to do with OpenResty or lua-nginx-module?*
libCling <http://root.cern.ch/drupal/content/cling-integrated-our-ci-tool>,
which is the library form of cling, would allow a whole new breed of
Nginx-based projects...
High-performance is one of the key features that Nginx offers; mix that
with LuaJIT and the lua-nginx-module and you get a high-performance dynamic
web application server.
Sadly, one weakness of OpenResty is the comparatively smaller selection of
web application libraries. Although, this is getting better thanks to the
efforts of contributors to the various modules that make up OpenResty.
With libCling, OpenResty can be taken one step further and introduce high
performance C/C++ to the dynamic platform.
Portable C/C++ libraries can then be shipped with the rest of the Lua
code-base instead of being compiled as modules that require modification
and fiddling with configuration files!
*There are some more awesome possibilities:*
- Dynamically compiling and/or linking platform-independent (*read as
LLVM byte code*) *C/C++* to rapidly prototype and refine Nginx modules
- Those modules can also expose Lua interfaces by calling the
lua-nginx-module public API:
lua_State * ngx_http_lua_get_global_state(ngx_conf_t *cf);
>
> ngx_http_request_t *ngx_http_lua_get_request(lua_State *L);
>
> void ngx_http_lua_add_package_preload(ngx_conf_t *cf, const char *package,
> lua_CFunction func);
>
>
- Even better, there could be *an Nginx module that compiles C/C++ and
make it available to Lua!*
- Manipulate Nginx at a very low level: No more sandboxes!
- (Okay, that's bad, but that's why compiling should probably be done
manually and the symbols of the trusted/hashed should be loaded once until
Nginx gets a HUP outside of a developer mode.)
- Take existing modules and make Lua-based interfaces without change
the original code!
- Implement small portions of code that require high performance
calculations. Implementing performant Bcrypt and Scrypt functions for Lua
would become super simple!
- Nginx's forking system is pretty useful because even if the loaded
LLVM code ends in a segmentation fault, it just halts a child process until
it is fixed.
- With a little help from a system like the lua-nginx-module, old
cold could be freed then the new code could be compiled and loaded.
Basically, with libCling and LuaJIT cooperating with one another, you can
have your cake and eat it too.
*Chase, you're crazy! That will never work and will be very hard to
implement!*
*
*
You probably didn't actually say that, but you may be thinking: "But, who
is going to make all this stuff?"
The answer is: hopefully some of the OpenResty contributors. One of them
being myself.
I hope to crank out a quick proof-of-concept Nginx module that compiles C
and makes it available to LuaJIT within a few weeks.
My C++ and C wisdom is rusty at best, so this may take longer; however, I'm
going to be optimistic and say that in my spare time I can implement this.