Hello!
2014-03-07 9:34 GMT-08:00 Lance:
> lua 的 os.date 当指定后面的 time 参数时,还会引起比较慢的系统调用吗?
>
这取决于具体的 OS 和 libc 实现。
在我的比较新的 Linux 系统上(较新的 glibc),使用 os.date("...", ngx.time())
并不会产生任何系统调用。我测试了下面这个小例子:
location /t {
content_by_lua '
print("hi")
for i = 1, 3 do
io.stderr:write(os.date("today is %A, in %B (%x)\\n",
ngx.time()))
end
ngx.say("hi")
';
}
在我的机器上用 strace 追踪对应的 nginx worker 进程显示一个典型的到 /t 的请求并没有触发多余的系统调用:
https://gist.github.com/agentzh/9421063
建议使用 strace 工具在你的系统上面进行确认 :)
Best regards,
-agentzh