-- 參數 "j" 啓用 JIT 編譯,參數 "o" 是開啓緩存必須的 local m = ngx.re.match("hello, 1234", regex, "jo")
local args = {...} or {} method_name(unpack(args, 1, table.maxn(args)))
local str = "abcde" print("case 1:", str:sub(1, 2)) print("case 2:", str.sub(str, 1, 2))
可使用一個 lj-releng 工具來掃描 Lua 代碼,定位使用 Lua 全局變量的地方。 lj-releng 的相關連接:https://github.com/openresty/openresty-devel-utils/blob/master/lj-releng
function isTableEmpty(t) return t == nil or next(t) == nil end
推薦使用 ngx_lua 模塊提供的帶緩存的時間接口,如 ngx.today, ngx.time, ngx.utctime, ngx.localtime, ngx.now, ngx.http_time,以及 ngx.cookie_time 等
實際中的應用,在 OpenResty 項目中應儘量讓網絡處理部分、文件 I/0 操做部分相互獨立,不要揉和在一塊兒
詞庫解釋html
名詞 | 解釋 |
---|---|
cdecl | A definition of an abstract C type(actually, is a lua string) |
ctype | C type object |
cdata | C data object |
ct | C type format, is a template object, may be cdecl, cdata, ctype |
cb | callback object |
VLA | An array of variable length |
VLS | A structure of variable length |
local ffi = require("ffi") ffi.cdef[[ int printf(const char *fmt, ...); ]] ffi.C.printf("Hello %s!", "world")
有些時候,ffi.C.xx_create 返回的不是具體的 cdata,而是整型的 handle。這會兒須要用 ffi.metatype 把 ffi.gc 包裝一下
```
local resource_type = ffi.metatype("struct {int handle;}", {
__gc = free_resource
})git
local function free_resource(handle)
...
endgithub
resource = ffi.new(resource_type)
resource.handle = ffi.C.xx_create()
```正則表達式
JIT
```
能夠經過 ngx-lj-gc-objs 工具看到指定的 Nginx worker 進程裏全部 trace 對象的一些基本的統計信息:https://github.com/openresty/stapxx#ngx-lj-gc-objs編程
咱們如何才能知道具體是哪一行 Lua 代碼上的哪個 NYI 原語終止了 trace 編譯呢?
答案很簡單。就是使用 LuaJIT 安裝自帶的 jit.v 和 jit.dump 這兩個 Lua 模塊。這兩個 Lua 模塊會打印出 JIT 編譯器工做的細節過程數組
完整的 NYI 列表:http://wiki.luajit.org/NYI緩存
可使用 ab 和 weighttp 這樣的工具對相應的服務接口進行預熱,以觸發 LuaJIT 的 JIT 編譯器開始工做
```cookie