best way to get a 1-second timer-tick?

Arnaud GRANAL serphen at gmail.com
Fri Apr 22 22:09:15 MSD 2011


On Fri, Apr 22, 2011 at 9:02 PM, Neil Mckee <neil.mckee.ca at gmail.com> wrote:
> Hello,
>

Hi Neil,

> I have written a module to implement sFlow in nginx  (nginx-sflow-module.googlecode.com).   I'm simulating a 1-second timer-tick by assuming that the request handler will be called at least once per second.   That's probably a safe assumption for any server that would care about sFlow monitoring,  but I expect there's a better way...
>
> I tried asking for a timer callback like this:
>
> ngx_event_t *ev = ngx_pcalloc(pool, sizeof(ngx_event_t));
> ev->hander = ngx_http_sflow_tick_event_hander;
> ngx_add_timer(ev, 1000);
>
> but (like most russian girls) the event never called me back.  It looks like I might have to hang this on a file-descriptor somehow,  but that's where I'm getting lost.  Any pointers would be most appreciated.
>

The main thing is that you should use ngx_add_event() here instead of
callocing the event struct directly and be careful of what you do with
ngx_http_finalize_request.


P.S.: hander = handler, but that's a detail.

A.



More information about the nginx-devel mailing list