Code Monkey home page Code Monkey logo

ngx-lua-request-time's Introduction

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.

ngx-lua-request-time's People

Contributors

kingluo avatar

Stargazers

rong fengliang avatar Michael Martin avatar Zeping Bai avatar theta avatar Jun Ouyang avatar  avatar

Watchers

 avatar  avatar

Forkers

bzp2010

ngx-lua-request-time's Issues

Segfault in lj_debug_funcname

I am trying to use this module in high-load environment but unfortunately, from time to time I get segfaults :/

Every coredump I've catched segfaults here:

#0  0x00001490360ba710 in lj_debug_funcname (L=L@entry=0x147f369c6b48, frame=frame@entry=0x147f375efe40, name=name@entry=0x7ffefab28f78) at lj_debug.c:323
#1  0x00001490360bad34 in lj_debug_getinfo (L=L@entry=0x147f369c6b48, what=0x4c580b "nl", what@entry=0x4c580a "Snl", ar=ar@entry=0x7ffefab28f70, ext=ext@entry=0) at lj_debug.c:497
#2  0x00001490360bb027 in lua_getinfo (L=L@entry=0x147f369c6b48, what=what@entry=0x4c580a "Snl", ar=ar@entry=0x7ffefab28f70) at lj_debug.c:542
#3  0x0000000000494a03 in ngx_http_lua_thread_traceback (coctx=0x1490320160a8, co=0x147f369c6b48, L=0x1) at /github/workspace/xxx/build/modules/lua-nginx-module-0.10.20/src/ngx_http_lua_util.c:3005
#4  ngx_http_lua_run_thread (L=L@entry=0x149036079380, r=r@entry=0x149031f99050, ctx=ctx@entry=0x149032016080, nrets=<optimized out>, nrets@entry=0)
    at /github/workspace/xxx/build/modules/lua-nginx-module-0.10.20/src/ngx_http_lua_util.c:1502
#5  0x000000000048bae2 in ngx_http_lua_read_body_resume (r=0x149031f99050) at /github/workspace/xxx/build/modules/lua-nginx-module-0.10.20/src/ngx_http_lua_req_body.c:1135
#6  0x0000000000499bd8 in ngx_http_lua_access_handler (r=0x149031f99050) at /github/workspace/xxx/build/modules/lua-nginx-module-0.10.20/src/ngx_http_lua_accessby.c:100
#7  0x000000000044fead in ngx_http_core_access_phase (r=0x149031f99050, ph=0x149032a9f750) at src/http/ngx_http_core_module.c:1083
#8  0x000000000044c045 in ngx_http_core_run_phases (r=0x149031f99050) at src/http/ngx_http_core_module.c:858
#9  0x000000000045cc67 in ngx_http_do_read_client_request_body (r=r@entry=0x149031f99050) at src/http/ngx_http_request_body.c:421
#10 0x000000000045d0cf in ngx_http_read_client_request_body_handler (r=0x149031f99050) at src/http/ngx_http_request_body.c:255
#11 ngx_http_read_client_request_body_handler (r=0x149031f99050) at src/http/ngx_http_request_body.c:245
#12 0x0000000000454eb4 in ngx_http_request_handler (ev=<optimized out>) at src/http/ngx_http_request.c:2248
#13 0x0000000000441b52 in ngx_epoll_process_events (cycle=<optimized out>, timer=<optimized out>, flags=1) at src/event/modules/ngx_epoll_module.c:902
#14 0x0000000000438b07 in ngx_process_events_and_timers (cycle=cycle@entry=0x149032a85410) at src/event/ngx_event.c:242
#15 0x000000000043fcd2 in ngx_worker_process_cycle (cycle=cycle@entry=0x149032a85410, data=data@entry=0x37) at src/os/unix/ngx_process_cycle.c:750
#16 0x000000000043e517 in ngx_spawn_process (cycle=cycle@entry=0x149032a85410, proc=proc@entry=0x43fc60 <ngx_worker_process_cycle>, data=data@entry=0x37, name=name@entry=0x4bd0ec "worker process", respawn=respawn@entry=-3)
    at src/os/unix/ngx_process.c:199
#17 0x000000000043f15b in ngx_start_worker_processes (cycle=cycle@entry=0x149032a85410, n=64, type=type@entry=-3) at src/os/unix/ngx_process_cycle.c:359
#18 0x000000000044057b in ngx_master_process_cycle (cycle=0x149032a85410) at src/os/unix/ngx_process_cycle.c:131
#19 0x00000000004195a6 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:382

Any ideas? Help will be much appreciated :)

I am using:

  • luajit2-2.1-20231117
  • lua-nginx-module-0.10.20
  • nginx 1.15.8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.