openresty / openresty/lua-nginx-module

Switch over to lua-resty-core and retire old CFunction-based Lua API impl

Open
#949 21 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

As originally discussed in #942, I'd like to discuss the option of forcibly switching over to lua-resty-core in this ngx_http_lua module and drop the existing CFunction-based Lua API implementation in the current ngx_http_lua module core.

The upside of this change is that we no longer have to maintain two parallel implementations of the same Lua API in both ngx_http_lua_module and lua-resty-core. And the ngx_http_lua_module core will be much smaller in terms of code size.

I propose the new lua_use_resty_core configuration directive for fine controls. By default, the resty.core module is automatically loaded right before running the init_by_lua* hook (if any). The user can avoid that by configuring the following directive in her nginx.conf:

lua_use_resty_core none;

Furthermore, the user can choose to load a selectively subset of submodules of resty.core.* like below:

# only load modules resty.core.regex, resty.core.shdict, and resty.core.req
lua_use_resty_core regex shdict req;

This leads to even a little bit smaller runtime memory footprint and less GC overhead (across those API function objects and containing Lua tables).

Or just load everything:

lua_use_resty_core all;

And loading everything under the resty.core.* namespace is the default.

A natural consequence of this change is that we also drop the long-time support of the standard Lua 5.1 interpreter in ngx_http_lua and the whole OpenResty. LuaJIT is already diverged a lot from it and it's becoming a big burden for us due to the lack of FFI in the standard Lua 5.1 interpreter, for example.

Another natural consequence of this is that ngx_http_lua_module will also depend on lua-resty-lrucache which is used by lua-resty-core's resty.core.regex submodule (for the compiled regex cache used by the ngx.re.* API).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review #942 and the current ngx_http_lua module core alongside lua-resty-core, including the init_by_lua* hook and the proposed lua_use_resty_core directive in nginx.conf. Done means the old CFunction-based API is retired, selective or full resty.core loading works, standard Lua 5.1 support is removed, and the lua-resty-lrucache dependency is accounted for.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua, nginx
Domain
api, backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.