请教春哥,请教各位前辈!
content_by_lua_file在使用时的问题:
nginx的配置文件:
location ~ ^/consume/search/([0-9]+)$ {
content_by_lua_block {
local cache = ngx.shared.my_caches
local key = ngx.var[1];
local val, err = cache:get(key)
if val then
ngx.say(val)
end
}
}
location ~ ^/consume/file/([0-9]+)$ {
lua_code_cache on;
content_by_lua_file lua/consume/getcache.lua;
}
getcache.lua文件内容如下:
package.path=package.path..'/usr/local/openresty/visitor/lua/consume/?.lua;;'
local cache = ngx.shared.my_caches
local key = ngx.var[1];
local val, err = cache:get(key)
if val then
ngx.say("result: ", val)
return
end
由此可见lua脚本内容相同,但是在同一台centos上对这两个location进行ab压力测试的时候,性能差距很大:
ab -n10000 -c100 -k http://ip地址:6699/consume/file/146100002
执行多次的结果:
Requests per second: 4054.52 [#/sec] (mean)
Requests per second: 1453.09 [#/sec] (mean)
Requests per second: 871.18 [#/sec] (mean)
Requests per second: 601.29 [#/sec] (mean)
Requests per second: 489.21 [#/sec] (mean)
ab -n10000 -c100 -k http://ip地址:6699/consume/search/146100002
执行多次的结果:
Requests per second: 20166.98 [#/sec] (mean)
Requests per second: 20267.33 [#/sec] (mean)
Requests per second: 21384.66 [#/sec] (mean)
Requests per second: 21459.09 [#/sec] (mean)
为什么content_by_lua_file 的性能损耗那么大了。求各位大神解答,不胜感激~