-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathi_worker.lua
45 lines (35 loc) · 999 Bytes
/
i_worker.lua
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
local _worker_count = ngx.worker.count()
local _worker_id = ngx.worker.id()
local ngx_shared = ngx.shared
local ipairs = ipairs
local stool = require("stool")
local modcache = require("modcache")
local ngx_thread = ngx.thread
local timer_every = ngx.timer.every
local config_dict = ngx_shared.config_dict
local handler_zero
-- dict 清空过期内存
local function flush_expired_dict()
local dict_list = {"config_dict","balancer_dict","ip_dict","limit_ip_dict"}
for _,v in ipairs(dict_list) do
ngx_shared[v]:flush_expired()
end
end
handler_zero = function ()
--清空过期内存
ngx_thread.spawn(flush_expired_dict)
end
local function handler_all_worker()
-- 每个 woker 进行 modcache 更新
modcache.upcheck()
end
--- 动态健康检查
local function healthcheck()
-- body
end
if _worker_id == 0 then
timer_every(120,handler_zero)
-- 执行后端健康检查
-- timer_every(1,healthcheck)
end
timer_every(1,handler_all_worker)