Hello! On Tue, Sep 1, 2015 at 5:11 PM, Mh C wrote: > I'm developing a module of nginx that connects to zookeeper. > You can see it on https://github.com/B12040331/nginx-zookeeper. > But I found the process that the module was in was neither master or worker. > I want to know is there any way to put a thread in master. > By design, the nginx master process should only listen to signals and do nothing else. One should avoid doing clever long-running things in master because 1. it may make master fragile and even crash, which is a disaster for the while service. 2. it may open security vulnerabilities since the master is usually run under a privileged system account like root. I think it's a better idea to run threads in an nginx worker process via init_worker_by_lua (you can only allow a single worker to run the thread with clever tricks like shdict or lua-resty-lock). Regards, -agentzh
Hello! On Wed, Sep 2, 2015 at 9:37 AM, Mh C wrote: > How to put a thread into worker process? Do I put it into worker process > when fork the worker? > As I said, just use a recurring ngx.timer.at() in init_worker_by_lua. Regards, -agentzh
Hello! On Wed, Sep 2, 2015 at 11:06 AM, Mh C wrote: > Is there any way to use C laguage to achieve it? > It's complicated and not really worth it at all IMHO :) The Lua solution I suggested is very fast and I doubt you can measure any different with a pure C solution since most of the heavy lifting is already done in pure C in the ngx_lua core. Regards, -agentzh