Now the modules themselves are requiring each other.
Example of a_helper module
local config = {
RRRR = 3,
XXXX = 7,
MMMM = false,
AAAA = true,
LLLL = false,
}
local a_helper = {
config = config,
info = {
a = 0,
b = 0,
c = 0,
d = 0,
},
data = {
aaa = false,
xxx = {},
bbb = {},
},
track = {
},
internal = {
yyxxaa = 0,
bbvvcc = false,
}
}
local b_helper = require "b_helper"
local logger = require "logger"
local utils = require "utils"
local macros = require "macros"
local decoder = require "sl_decoder"
local opt = require "opt"
local request = require "request"
local new = require "new"
local cfg = require "cfg"
function a_helper.init(config)
math.randomseed(os.clock() * 1000000)
if math.random(0,100) > 98 then
logger.log('2', "Mode A")
end
if math.random(0,100) > 90 then
logger.log('2', "Mode B")
end
end
function a_helper.doSomething()
math.randomseed(os.clock() * 1000000)
logger.log('2', "log log")
logger.log('2', request.info)
end
return a_helper
Then i have a location which uses all the modules themselves
location ~ ^/lua/modules {
more_set_headers "Access-Control-Allow-Credentials: true";
default_type 'application/json';
expires -1000000;
content_by_lua_file /all_modules.lua;
}
Now the all_modules.lua is doing stuff with all the modules.
cfg.init()
logger.init()
a_helper.init()
a_helper.config.AAAA = false
b_helper.init()
request.arg_id = ngx.var.arg_ID or ""
request.arg_key = ngx.var.arg_KEY or ""
a_helper.doSomething()
local aaa = function()
-- Check some stuff..
-- A lot of code...
a_helper.doSomething()
-- More usage of logger and all modules
end
-- Usage of logger and all modules
ngx.say(request.result)
Now the memory is increasing and I fill like I'm doing something wrong.
How can I load in a good way several modules?
How can I use them, in the best practices way, inside each other?
How can I use them, in the best practices way, in the content_by_lua_file?
How can I easily check for that memory leak?
Seems like I'm missing something with the modules. It is like some of the data is never free'd or something.
A help will be much appreciated.