https://github.com/kingluo/ngx-lua-request-time
openresty hook: record the lua execution time per request in ngx.ctx via LD_PRELOAD
https://github.com/kingluo/ngx-lua-request-time
linker luajit nginx openresty profiling
Last synced: 8 months ago
JSON representation
openresty hook: record the lua execution time per request in ngx.ctx via LD_PRELOAD
- Host: GitHub
- URL: https://github.com/kingluo/ngx-lua-request-time
- Owner: kingluo
- License: bsd-3-clause
- Created: 2023-04-15T06:55:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-12T09:50:38.000Z (over 2 years ago)
- Last Synced: 2025-03-30T09:11:33.640Z (9 months ago)
- Topics: linker, luajit, nginx, openresty, profiling
- Language: C
- Homepage:
- Size: 19.5 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ngx-lua-request-time
It records the lua execution time per request in `ngx.ctx`, in microsecond.
Check this blog for details:
http://luajit.io/posts/openresty-lua-request-time/
The request time is the sum of the following metrics:
* `lua_resume`
* phases
* REWRITE
* ACCESS
* CONTENT
* BALANCER
* `lua_pcall`
* filters
* header_filter
* body_filter
**It's non-intrusive and zero-cost.**
Usage:
```bash
NGX_LUA_REQUEST_TIME_VAR_NAME=openresty_request_time_us \
LD_PRELOAD=/opt/ngx-lua-request-time/ngx_lua_request_time.so \
openresty -p $PWD -c nginx.conf
```
* `NGX_LUA_REQUEST_TIME_VAR_NAME`: variable name in `ngx.ctx.`
* `LD_PRELOAD`: preload the `ngx_lua_request_time.so`
## build
```bash
make
# output ngx_lua_request_time.so
```
## demo
*Do not use the Alpine docker image, where the musl libc seems not LD_PRELOAD compatible.*
* [openresty](https://github.com/kingluo/ngx-lua-request-time/tree/main/demo/openresty)
* [apisix](https://github.com/kingluo/ngx-lua-request-time/tree/main/demo/apisix)