1、可以用NGINX较新的版本,引入aio
thread支持,可以缓解(并非根治)File I/O调用的阻塞。
2、自己用FFI+LUA协程+异步文件读写IO去封装实现无阻塞文件访问LUA文件访问函数库。
发件人:
YuanSheng Wang
<yuan...@openresty.org>
收件人:
openresty@googlegroups.com,
日期:
2016/01/21
18:20
主题:
Re: [openresty]
用lua做文件读写操作有无高性能的解决方法?
发件人:
openresty@googlegroups.com
所有的文件 IO 操作,都是同步阻塞的,他们都会破坏
OpenResty 的事件循环机制。所以要尽量避免。
如果每次读取的文件是同一个,完全可以把文件内容缓存到内存中。
更推荐的玩法是把文件内容,解析到redis这类
KV 数据库中,这样后期就可以通过网络方式解决,并且可以简化问题处理。
2016-01-21 17:14 GMT+08:00 yongjian xu <yongj...@gmail.com>:
概述:
我尝试在header filter阶段用lua读取一个小文件,并根据里面的内容,修改response
header。结果发现对性能的影响很大。
说明:
目前采用io.open等I/O操作函数以及采用ffi C库的I/O函数都发现有很大的性能问题。
初步分析:
原因目前看来是:1)luajit不支持io.open, io.read,
io.close等调用;2)luajit不支持ffi.cdef等
提问:
关于高效地进行文件操作,不知道大家有什么经验?
--
--
YuanSheng Wang
---------------------------------------
My Github: https://github.com/membphis
OpenResty lover ^_^
--
--------------------------------------------------------
ZTE Information Security Notice: The information contained in this mail (and any attachment transmitted herewith) is privileged and confidential and is intended for the exclusive use of the addressee(s). If you are not an intended recipient, any disclosure, reproduction, distribution or other dissemination or use of the information contained is strictly prohibited. If you have received this mail in error, please delete it and notify us immediately.
--------------------------------------------------------
ZTE Information Security Notice: The information contained in this mail (and any attachment transmitted herewith) is privileged and confidential and is intended for the exclusive use of the addressee(s). If you are not an intended recipient, any disclosure, reproduction, distribution or other dissemination or use of the information contained is strictly prohibited. If you have received this mail in error, please delete it and notify us immediately.