Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
介绍 ngx.today, ngx.time, ngx.utctime, ngx.localtime, ngx.now, ngx.http_time,以及 ngx.cookie_time 基本使用办法以及其原理
关键点:
事实上,在 Nginx/Openresty 中,会经常使用到获取时间操作,通常一次请求最少有几十次获取时间操作,当单核心 RPS/QPS 达到 10K 以上时,获取时间操作往往会达到 200K+量级的调用,是一个非常高频的调用。所以 Nginx 会将时间和日期进行缓存,并非每次调用或每次请求获取时间和日期。
推荐 使用 ngx_lua 模块提供的带缓存的时间接口,如
ngx.today
,ngx.time
,ngx.utctime
,ngx.localtime
,ngx.now
,ngx.http_time
,以及ngx.cookie_time
等。ref:
#312