Event-driven handler

Marcus Clyne eugaia at gmail.com
Wed Feb 18 22:34:46 MSK 2009


 > What do you need to do?

I'm generating pages based on simple templates, but which could do all 
manner of things, including getting data from databases. I don't want to 
use PHP/Python etc because the overhead would be very high and not very 
practical for what I'm doing.

 > You should also read Nginx source code to understand how things works.

Yep, been doing that. :-)

Ok, I understand that I shouldn't call ngx_http_output_filter etc from 
within my thread.

You mentioned setting up a loop that checked every 0.001 secs.  How 
about a solution like this:

[handler] (as mentioned before)
- passes off request to content generator
- returns immediately to Nginx with NGX_DONE

[content generator]
- generates content
- in threadsafe fashion, puts the output content in a queue of responses 
to be returned

[in Nginx]
- loop that checks every e.g. 0.001 secs to see if there are any 
responses (headers and/or content)
- checks for responses in threadsafe fashion, and if there are, calls 
ngx_http_output_filter etc

This last loop is integrated into the co-operative multi-tasking 
architecture of Nginx, so we don't need
to worry about calls to ngx_http_output_filter not being threadsafe.

Is it possible to set up such a loop in Nginx?  How would I set it up?

Alternatively, I would prefer to have an event-driven system whereby I 
wouldn't need a loop to check whether
my responses were ready.  Is it possible to trigger non-IO events in 
Nginx, such that once triggered, Nginx
would handle them properly (even if they were called from within a 
different thread)?


I've looked at your WSGI code a bit as well as the Nginx source.  I will 
be looking at it some more too.

Thanks,

Marcus.





More information about the nginx mailing list