upyun / lua-resty-checkups

Manage Nginx upstreams in pure Lua.
259 stars 65 forks source link

os.time() 是否应该替换成 ngx.time #10

Closed liuyangc3 closed 7 years ago

liuyangc3 commented 7 years ago

in base.lua

local CHECKUP_TIMER_KEY = "checkups:timer:" .. os.time()

os.time 这个函数 老生常谈了,这里是否应该使用消耗更小的 ngx.time 更为合适?

yejingx commented 7 years ago

我想你指的是 ngx.time 吧?

  1. ngx.time 不能在 init 阶段使用。
  2. checkups 通常是在 init_by_lua 的时候被初始化的,并且只有一次,所以无所谓系统调用带来的性能损耗。
liuyangc3 commented 7 years ago

谢谢,已修正

在 init_worker.lua 中也不能用么,我是在 init_worker.lua 看到的这个

-- only one checkups timer is active among all the nginx workers
checkups.create_checker()
liuyangc3 commented 7 years ago

点错了

yejingx commented 7 years ago

在 init_worker.lua 中也不能用么,我是在 init_worker.lua 看到的这个

也可以在 init_worker 中使用,我们这么做是为了通用性考虑。

之前因为 ngx_lua 的限制,prepare_checkercreate_checker 都放在了 init_worker 里,现在我们一般会把 prepare_checker 放到 init 里。

liuyangc3 commented 7 years ago

谢谢,目前还没看到 prepare_checker 这块,另外回复很快, 赞:+1: