lua randomseed per worker
This commit is contained in:
parent
66aecbd0b2
commit
4896b064ca
6 changed files with 51 additions and 3 deletions
26
rootfs/etc/nginx/lua/lua_ingress.lua
Normal file
26
rootfs/etc/nginx/lua/lua_ingress.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
local _M = {}
|
||||
|
||||
local seeds = {}
|
||||
local original_randomseed = math.randomseed
|
||||
math.randomseed = function(seed)
|
||||
local pid = ngx.worker.pid()
|
||||
|
||||
if seeds[pid] then
|
||||
ngx.log(ngx.WARN,
|
||||
string.format("ignoring math.randomseed(%d) since PRNG is already seeded for worker %d", seed, pid))
|
||||
return
|
||||
end
|
||||
|
||||
original_randomseed(seed)
|
||||
seeds[pid] = seed
|
||||
end
|
||||
|
||||
local function randomseed()
|
||||
math.randomseed(ngx.time() + ngx.worker.pid())
|
||||
end
|
||||
|
||||
function _M.init_worker()
|
||||
randomseed()
|
||||
end
|
||||
|
||||
return _M
|
||||
Loading…
Add table
Add a link
Reference in a new issue