Hi, guys
I have a memory leak problem. As follows:
openresty configure file:
http{
...
init_by_lua_file /root/LeakTest/LTest/lua/init/init.lua;
init_worker_by_lua_file /root/LeakTest/LTest/lua/init/init_worker.lua;
....
}
Code in /root/LeakTest/LTest/lua/init/init_worker.lua:
local delay = 0
local new_timer = ngx.timer.at
local log = ngx.log
local ERR = ngx.ERR
local check
local set_key = "data_set_"..ngx.worker.id()
local q_key = "data_queue_"..ngx.worker.id()
check = function(premature)
local red = redis:new()
if not premature then
-- do the health check or other routine work
while true do
local rxdata, err = red:spop(set_key)
while not err and rxdata ~= nil do
db_query.write_nodedata(cjson.decode(rxdata))
rxdata, err = red:spop(set_key)
end
red:brpop(q_key, 0)
end
end
end
local ok, err = ngx.timer.at(delay, check)
if not ok then
log(ERR, "failed to create timer: ", err)
return
end
Module db_query(db_query.lua):
local _M = {}
function _M.write_nodedata(data)
local pg = pgmoon.new({
--host = "127.0.0.1",
--port = "5432",
host = "10.162.67.28",
port = "5433",
database = "dataserver",
user = "dataserver",
password = "password"
})
local returnValue = pg:connect()
if returnValue ~= true then
ngx.log(ngx.ERR, "not connect returnValue is : ", returnValue)
return false
end
local sql = "INSERT INTO ..."
local res = pg:query(sql)
ngx.log(ngx.ERR, "aaaaaaaaaaa timer sql: ", sql)
pg:keepalive()
return res
end
return _M
And I require these modules in init.lua:
cjson = require "cjson"
error_table = require "error_code"
db_query = require "db_query"
redis = require "capsule_redis"
comm_func = require "common_function"
pgmoon = require("pgmoon")
Module capsule_redis(capsule_redis.lua):
https://gist.github.com/moonbingbing/9915c66346e8fddcefb5
Module pgmoon:
https://github.com/leafo/pgmoon
I modify pgmoon in it's pgmoon/init.lua, change "return sock:setkeepalive(...)" to "return sock:setkeepalive(50, 20)", for it seems that the original one don't use the connect pool correctly.
There are 10 redis queues, I wrote this OR service (10 OR workers )to put the data in these 10 redis queues into Postgres.
I use pgmoon in OR to connect to Postgres.
I found that the longer this OR service runs, the more memory it consumes, and memory consume never goes down, is there any memory leak issues in my code?
SOS~~please