ngx_lua 一些性能分析方法,ngx_lua分析方法


来自  邮件列表里! 转载下来。记录下,说不定以后用的到 ; 


原文地址:https://groups.google.com/forum/#!topic/openresty/bOwgPymXQzg



我们有一整套的基于 systemtap 的工具链可以用于在线或者离线的性能分析。 

你的 nginx 进程的 CPU 使用率如果很高的话,可以使用 C 级别的 on-CPU 时间火焰图工具对你最忙的 nginx worker 进程进行采样: 

    https://github.com/agentzh/nginx-systemtap-toolkit#sample-bt 

如果你的 nginx 进程的 CPU 很低,但请求延时很高,则有两种可能: 

1. 你的 nginx 阻塞在了某些阻塞的 IO 操作(比如文件 IO)或者系统的同步锁上,此时你可以使用 C 级别的 off-CPU 
时间火焰图工具对某个典型的 nginx worker 进程进行采样: 

   https://github.com/agentzh/nginx-systemtap-toolkit#sample-bt-off-cpu 

如果你发现 Lua 代码占用了大部分的 CPU 时间,则可以进一步使用 ngx-lua-exec-time 工具加以确认: 

    https://github.com/agentzh/stapxx#ngx-lua-exec-time 

进一步地,你可以使用 Lua 代码级别的 on-CPU 火焰图工具在 Lua 层面上分析 CPU 时间的分布。如果你使用的是 LuaJIT 
2.0.x,则可以使用下面这个工具进行采样: 

    https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-lua-bt 

如果你使用的是 LuaJIT 2.1,则可以使用 lj-lua-stacks 工具进行采样: 

    https://github.com/agentzh/stapxx#lj-lua-stacks 

2. 你的 nginx 通过 ngx_lua 的 cosocket 或者 ngx_proxy 这样的 upstream 
模块和上游服务进行通信时,上游服务的延时过大。此时你可以分别使用 
ngx-lua-tcp-recv-time、ngx-lua-udp-recv-time 以及 ngx-single-req-latency 
工具进行分析: 

    https://github.com/agentzh/stapxx#ngx-lua-tcp-recv-time 

    https://github.com/agentzh/stapxx#ngx-lua-udp-recv-time 

    https://github.com/agentzh/stapxx#ngx-single-req-latency 


相关内容

    暂无相关文章