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

Maxim Dounin mdounin at mdounin.ru
Sat Apr 23 13:04:02 MSD 2011


Hello!

On Fri, Apr 22, 2011 at 09:09:15PM +0300, Arnaud GRANAL wrote:

> 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.

No, you are wrong.

Maxim Dounin



More information about the nginx-devel mailing list