perf: 一个小型 ngx resty lua 库,用于基准测试函数的内存和吞吐量
安装
如果您尚未设置 RPM 仓库订阅,请 注册。然后,您可以继续以下步骤。
CentOS/RHEL 7 或 Amazon Linux 2
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install lua-resty-perf
CentOS/RHEL 8+、Fedora Linux、Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install lua5.1-resty-perf
要在 NGINX 中使用此 Lua 库,请确保已安装 nginx-module-lua。
本文档描述了 lua-resty-perf v1.0.4,发布于 2021 年 4 月 14 日。
一个简单的 resty lua 库,用于基准测试函数的内存和吞吐量。
local function mycode()
local x = {}
for i = 1, 1e3 do
local now = ngx.now()
now = now - 45 + i
x[i] = now
end
return x
end
perf.perf_time("mycode cpu profiling", function()
mycode()
end)
perf.perf_mem("mycode memory profiling", function()
mycode()
end)
docker run -it --rm -v ${PWD}/test.lua:/test.lua -v ${PWD}/lib/resty/perf.lua:/lib/resty/perf.lua openresty/openresty:xenial resty /test.lua

GitHub
您可以在 nginx-module-perf 的 GitHub 仓库 中找到此模块的其他配置提示和文档。