Event loop plus another event loop

Yichun Zhang (agentzh) agentzh at gmail.com
Wed Jan 21 22:00:14 UTC 2015


Hello!

On Sat, Jan 17, 2015 at 5:10 PM, Marat Dakota wrote:
> I'm writing a module for a piece of software which works the same way.
> So, what I need is a mechanism to call both handlers in a busy loop:
>
> while (true) {
>    `process events and call callbacks`();
>    `process my piece of software events and call callbacks`();
> }
>

Well, nginx is a single-threaded application (for each worker process)
so you can only have one event loop, otherwise other event loops can
always block the main event loop in the nginx core, ruining the
performance.

You can register the fd of the socket created by your 3rd-party
libraries into nginx's event model and use nginx's event loop to
dispatch read/write events on it on the library's behalf.

For example, our ngx_drizzle module integrates the 3rd-party
libdrizzle library into nginx to talk to MySQL servers nonblockingly:

    https://github.com/openresty/drizzle-nginx-module#readme

And our ngx_postgres module integrates the official libpq library from
PostgreSQL in a similar way:

    https://github.com/FRiCKLE/ngx_postgres#readme

Regards,
-agentzh



More information about the nginx-devel mailing list