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 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值