Skip to content

Commit

Permalink
optimize heartbeat performance by light thread
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveryunchang committed Nov 26, 2017
1 parent aec0e04 commit 31fc860
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/resty/checkups/heartbeat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ local now = ngx.now
local tcp = ngx.socket.tcp
local update_time = ngx.update_time

local spawn = ngx.thread.spawn
local wait = ngx.thread.wait

local get_shm = subsystem.get_shm
local mutex = get_shm("mutex")
local state = get_shm("state")
Expand Down Expand Up @@ -444,8 +447,15 @@ function _M.active_checkup(premature)
return
end

local thread = {}
for skey in pairs(base.upstream.checkups) do
cluster_heartbeat(skey)
thread[#thread + 1] = spawn(cluster_heartbeat, skey)
end

for _,v in ipairs(thread) do
if v then
wait(v)
end
end

local interval = base.upstream.checkup_timer_interval
Expand Down

0 comments on commit 31fc860

Please sign in to comment.