apisix
apisix copied to clipboard
help request: keeping redis connection alive
Description
Hello, I've been working on the limit-req plugin with redis and I realized apisix creates a new connection for every single request, so I think maybe I can alter this behaviour and if I can keep a single connection, it could perform faster after getting rid of three-way handshake.
Maybe you tried it already and it is a bad idea but I really need to get higher numbers 🙏
I've played a little in apisix/plugins/limit-req/limit-req-redis.lua
function _M.new(plugin_name, conf, rate, burst)
local red, err = redis.new(conf)
if not red then
return red, err
end
local self = {
red = red,
conf = conf,
plugin_name = plugin_name,
burst = burst * 1000,
rate = rate * 1000,
}
return setmetatable(self, mt)
end
function _M.incoming(self, key, commit)
local conf = self.conf
local red = self.red
if not red then
return red, err
end
return util.incoming(self, red, key, commit)
end
So it creates a connection once and keeps it under "self". My problem here is that it somehow terminates this connection after first request and the rest throws this error:
2024/06/25 18:29:23 [error] 242482#242482: *3933 [lua] limit-req.lua:171: phase_func(): failed to limit req: closed, client: x.x.x.x, server: _, request: "GET /test1/x HTTP/2.0", host: "xyz.com"
I failed to find the trigger that closes connection. Could you guide me please?
Environment
- APISIX version (run
apisix version
): 3.9 - Operating system (run
uname -a
): Ubuntu 22.04 - OpenResty / Nginx version (run
openresty -V
ornginx -V
): openresty/1.21.4.1 - etcd version, if relevant (run
curl http://127.0.0.1:9090/v1/server_info
): - APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run
luarocks --version
):