Skip to content

openresty hook: record the lua execution time per request in ngx.ctx via LD_PRELOAD

License

Notifications You must be signed in to change notification settings

kingluo/ngx-lua-request-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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.<var>
  • LD_PRELOAD: preload the ngx_lua_request_time.so

build

make
# output ngx_lua_request_time.so

demo

Do not use the Alpine docker image, where the musl libc seems not LD_PRELOAD compatible.

About

openresty hook: record the lua execution time per request in ngx.ctx via LD_PRELOAD

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published