openresty的ngx.timer.at
openresty的ngx.timer.at真是个强大的方法。
- 例如某些函数不可以在一些NGINX的执行阶段使用时,可以ngx.timer.at API 创建一个零延迟的timer,在timer中去处理。
- 遇到一些高延迟的函数,因为定时调用是在后台运行,并且他们的执行不会增加任何客户端的响应时长
local function save_message(premature)
ngx.sleep(5)
local file = assert(io.open('/tmp/test.log','a+'))
file:write(string.format("timer=====> %s %s\n", ngx.time(), "in timer"))
file:close()
end
local file = assert(io.open('/tmp/test.log','a+'))
file:write(string.format("out tomer 1=====> %s %s\n", ngx.time(), "out timer 1"))
file:close()
ngx.sleep(5)
local file = assert(io.open('/tmp/test.log','a+'))
file:write(string.format("out tomer 2=====> %s %s\n", ngx.time(), "out timer 2"))
file:close()
--ngx.sleep(5)
local ok, err = ngx.timer.at(0, save_message)
if not ok then
ngx.log(ngx.ERR, "[blm-metric] failed to create timer: ", err)
end
ngx.say("success")
结果将在5秒后返回,查看日志,每隔5秒分别打印出三次的结果,
openresty的ngx.timer.at的更多相关文章
- openresty跑定时任务配置、ngx.timer.every接口使用
openresty的定时任务是要跟worker绑定的.如果不绑定特定的worker,那么所有启动的woker都会去执行定时任务. 一般情况下默认绑定worker_id=0的,这样在nginx整个进程里 ...
- ngx_lua_API 指令详解(一)ngx.timer.at 指令
语法: ok,err = ngx.timer.at(delay,callback,user_arg1,user_arg2 ...) 上下文: init_worker_by_lua *,set_by_l ...
- OpenResty之ngx.var.VARIABLE
1. ngx.var.VARIABLE syntax: ngx.var.VAR_NAME context: set_by_lua*, rewrite_by_lua*, access_by_lua*, ...
- OpenResty之ngx.ssl
翻译自: ngx.ssl - Lua API for controlling NGINX downstream SSL handshakes 1. 概要 # 注意:如果你使用的是 OpenResty ...
- OpenResty之ngx.shared.DICT
参考链接: resty.core.shdict ngx_shared.DICT 源码正文: dict.lua 部分源码如下: local ffi = require 'ffi' local base ...
- Openresty 与 Tengine
Openresty 与 Tengine Openresty和Tengine基于 Nginx 的两个衍生版本,某种意义上他们都和淘宝有关系,前者是前淘宝工程师agentzh主导开发的,后者是淘宝的一个开 ...
- ngx.ctx
https://github.com/openresty/lua-nginx-module#ngxctx 要点 生命周期和请求一致 每个请求的ngx.ctx是相互独立的,包括ngx.location. ...
- openresty + lua 4、openresty kafka
kafka 官网: https://kafka.apache.org/quickstart zookeeper 官网:https://zookeeper.apache.org/ kafka 运行需要 ...
- ngx_lua_API 指令详解(二)ngx.re.match/find/gmatch/sub/gsub指令集合
1.先来个官方的ngx.re.match location /ngx_re_match { default_type text/html; content_by_lua_block { local m ...
随机推荐
- lwIP配置文件opt.h和lwipopts.h
如何去配置lwip,使它去适合不同大小的脚,这就是lwIP的配置问题.尤其是内存的配置,配置多了浪费,配置少了跑不了或者不稳定(会出现的一大堆莫名奇妙的问题,什么打开网页的速度很慢啊?什么丢包啊,什么 ...
- 使用mysqldump命令备份恢复MySQL数据库
1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dump file] 上述命令将指定数据库备份到某dump文 ...
- fieldset——一个不常用的HTML标签
fieldset 标签 -- 对表单进行分组 在form表单中,我们可以对form中的信息进行分组归类,如注册表单的form,我们可以将注册信息分组成 基本信息(一般为必填) 详细信息(一般为可选) ...
- Substrings(hdu 4455)
题意: 给定一个序列ai,个数为n.再给出一系列w:对于每个w,求序列中,所有长度为w的连续子串中的权值和,子串权值为子串中不同数的个数. /* dp[i]表示长度为i的序列不同元素个数之和. 考虑从 ...
- 在Servlet中出现一个输出中文乱码的问题
添加:reqeust.setCharacterEncoding("utf-8");
- 【CF1027F】Session in BSU(dsu,基环树)
题意:给出n场考试,每场考试有2天可以通过(第ai与bi天).每天最多参加一场考试,现在要求所有考试全部通过的最小天数 n<=1e6,1<=a[i]<b[i]<1e9 思路:F ...
- 解决cursor未关闭造成的死锁
参考:https://blog.csdn.net/zc474235918/article/details/72731363/ https://blog.csdn.net/zmx729618/artic ...
- url 拼接的一个模块furl
from furl import furl getlongtexturl="https://weibo.com/p/aj/mblog/getlongtext" params={ & ...
- python 微博评论获取的时候日期格式化
# -*- coding: utf-8 -*- # @Time : 2018/03/05 10:57 # @Author : cxa # @File : testDataTime.py # @Soft ...
- Oracle基础 12 对象 objects 同义词/序列/试图/索引
--创建同义词create public synonym employees for hr.employees; --公共同义词需要 create public synonym 权限 表的所有用户授 ...