Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new_timer时绑定到0 == ngx.worker.id()的问题 #5

Open
Ajax001001 opened this issue Nov 3, 2020 · 1 comment
Open

new_timer时绑定到0 == ngx.worker.id()的问题 #5

Ajax001001 opened this issue Nov 3, 2020 · 1 comment

Comments

@Ajax001001
Copy link

Ajax001001 commented Nov 3, 2020

你好,在client.lua中有这样一段代码
if 0 == ngx.worker.id() and heartbeat_timer == nil then local ok, err = new_timer(delay, check) end
我的理解 0 == ngx.worker.id() 是为了避免在多个worker进程下都执行该定时器,所以只绑定到workerid为0的worker进程下。
但是当我kong restart重启时,worker进程有4个,当前工作的worker id有可能是从0-3任何一个,如果恰巧不是0,就导致trimer不会被执行,造成链路不上报。
所以我把0 == ngx.worker.id()给去掉了,请问这样可行吗?会有什么问题?
谢谢。

@lemens
Copy link

lemens commented Dec 31, 2020

可以在handler.lua sw_client:startBackendTimer(config) 前获取一下当前worker id并传递到client.lua中,作为指定执行上报的worker id,避免多个worker都执行上报任务。具体修改方式:
handler.lua:
config.worker_id = ngx.worker.id()
sw_client:startBackendTimer(config)
client.lua:
local worker_id = config.worker_id
if worker_id == ngx.worker.id() and heartbeat_timer == nil then

可以解决部署环境获取不到id为0的worker导致trace数据无法上报的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants