Hello!
On Tue, Jul 1, 2014 at 4:41 AM, Jerome Lafon wrote:
> How could I do to write in a file using a non blocking call?
There is no such thing as nonblocking mode on normal file descriptors
for many POSIX-style operating systems including Linux.
We could use the kernel AIO feature but it has many limitations on
Linux which is of little practice merits.
A common workaround is to introduce extra OS threads but OS threads
add quite some complexity and have their own (relatively large)
overhead.
> Can I use io.open() directly?
>
You can. But better cache and share the file descriptor yourself on
the Lua land (to save the open and close syscalls) and prevent
flushing big volume of data onto file that would block the nginx event
loop significantly.
File I/O in nginx is usually blocking (unless with AIO enabled, but
AIO has its own drawbacks) and better keep the file operations small.
You can always quantitatively measure the actual blocking effect in a
live nginx worker process via tools like epoll-loop-blocking-distr
(
https://github.com/openresty/stapxx#epoll-loop-blocking-distr ) and
off-CPU flame graphs
(
https://github.com/openresty/nginx-systemtap-toolkit#sample-bt-off-cpu
).
Best regards,
-agentzh