Nginx mutli-threaded plugin

Maxim Dounin mdounin at mdounin.ru
Tue Jan 1 21:19:22 UTC 2013


Hello!

On Tue, Jan 01, 2013 at 11:57:30PM +0530, Fasih wrote:

> Hi guys
> 
> I need to write a plugin which does some CPU intensive work. I want to be
> able to create a thread which does some work and once done post an event
> into nginx thread via ngx_add_timer. I tried compiling my plugin with
> NGX_THREADS=pthread but that doesnt configure saying that the threading
> support is broken.  I can obviously switch to a single threaded mode but
> that would be significantly difficult for me and would prefer to use only
> as the very last resort.
> 
> Can you please advice how to go about doing this? I am considering pulling
> out the usage of 'ngx_event_timer_mutex' outside #if NGX_THREADS. Frankly I
> am surprised how no other plugin had this kind of requirement, the "broken
> support" commit has been there since quite some time now.

Threading support as currently present was an experiment, and it's 
broken for a long time (some very limited part of it is still used 
on win32, but it's different story).  I wouldn't expect you'll be 
able to work with threads without problems.

> One final question, if I do the CPU intensive work in the nginx thread and
> I have <cpu-cores> number of workers, how would the system behave? Will
> accept_mutex on/off change the behavior?

Accept mutex only ensures no two processes try to accept new 
connections at the same time, and it doesn't care how do you 
handle requests.  Obviously enough it will change the behaviour, 
much like in any other case.

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx-devel mailing list