Nginx Module Concurrency Query

Maxim Dounin mdounin at
Fri Jul 1 18:07:54 MSD 2011


On Fri, Jul 01, 2011 at 09:40:20AM -0400, Danny Glover wrote:

> I have been trying to get a simple nginx_module working. I referred
> and found it very
> useful. 
> The module takes "" and
> sleeps for few sec and simply prints the URI. 
> Here is the code :-


>   usleep(1500000);


> The response time was 11376ms, 7587ms, 3804ms for 30, 20, 10 concurrency
> respectively.  
> I am not sure what I am missing. 
> Can someone please guide me on how do I make this module scale? 

The behaviour you see is expected: you can't sleep as it will 
block all requests in a worker process.  Welcome to event-based 
programming. :)

You have to arm timer and return back to event loop, then continue 
processing once event fires.  You may take a look how to do this 
in standard limit_req module, though it will require some adaption 
for handler module.  In particular, you'll have to return NGX_DONE 
and then finalize request yourself, much like it's done when 
reading request body.

Maxim Dounin

More information about the nginx mailing list