1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
function mcp_config_pools()
-- print("CONFIG GARBAGE: " .. collectgarbage("count"))
local b1 = mcp.backend('b1', '127.0.0.1', 12101)
return mcp.pool({b1})
end
-- the same fgen should be fine for the whole test. it doesn't matter how
-- complicated each individual fgen is, just that we're stacking them and
-- routing them.
-- Even with just one item linked they'll have all of the request/result/etc
-- objects referenced.
function basic_fgen(p)
local fgen = mcp.funcgen_new()
local h = fgen:new_handle(p)
fgen:ready({ n = "foo", f = function(rctx)
return function(r)
local k = r:key()
if string.find(k, "collect$") then
collectgarbage()
collectgarbage()
local mem = collectgarbage("count")
return "SERVER_ERROR " .. tostring(mem) .. "\r\n"
elseif string.find(k, "go$") then
return rctx:enqueue_and_wait(r, h)
else
return "SERVER_ERROR unknown key: " .. k .. "\r\n"
end
end
end})
return fgen
end
function mcp_config_routes(p)
local map = {
["one"] = basic_fgen(p),
["two"] = basic_fgen(basic_fgen(p)),
["three"] = basic_fgen(basic_fgen(basic_fgen(p))),
}
-- "leak" an fgen on purpose.
-- this gets a cleanup routine through the GC instead of directly during
-- dereferencing.
basic_fgen(p)
-- defaults are fine. "prefix/etc"
local router = mcp.router_new({
map = map,
})
mcp.attach(mcp.CMD_MG, router)
end
|