Hello!
On Wed, Aug 20, 2014 at 9:48 AM, Stefan Parvu wrote:
> If I understood right the way nginx and openresty handles access to disk and
> files is by blocking at the worker level. Correct ?
>
Yes, unless AIO is used (but some file related syscalls like stat can
still block) because there is no such thing as "nonblocking file IO".
> Suppose I have a simple LUA function which opens a JSON file, writes some
> info to the file, closes it, for example when
> a new user has been registered to our system.
Maybe you should really use an external database or a simpler
key-value store exposing a socket interface for it?
> Now if I have an OpenResty
> installation where NGINX has been configured
> to run on 4 or 6 workers, how can I ensure consistency to the file ?
>
If you really want to write to files in OpenResty, you need to use
lua-resty-lock to protect it:
https://github.com/openresty/lua-resty-lock
Again, this can be way less efficient than using a socket-based
external data service as suggested above.
> 1. How one would ensure data consistency when having NGINX running on 2,4
> workers ?
>
See above.
> 2. Would be easier to handle the access to the file in-memory ? Like for
> example memcached or redis ?
Yes, sure. Also, redis has persistence support itself:
http://redis.io/topics/persistence
> Anyway at some point data should arrive to the flile itself ? For example in
> a case of a system crash or
> whatever else ...
>
See above.
> 3. What other suggestions ?
>
Avoid file IO wherever possible in the context of nginx.
Regards,
-agentzh