best way to get a 1-second timer-tick?
mdounin at mdounin.ru
Sat Apr 23 13:03:19 MSD 2011
On Fri, Apr 22, 2011 at 11:02:01AM -0700, Neil Mckee wrote:
> 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);
1. You have to supply ev->log.
2. You have to supply ev->data. It is expected to be valid
pointer to connection structure or something compatible, at least
#define ngx_event_ident(p) ((ngx_connection_t *) (p))->fd
should be available as ngx_event_ident(ev->data) for logging
purposes (not required to be valid though).
2. You have to make sure appropriate event structure is still
there when timer will be called (i.e. make sure to remove timer on
> 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.
No, you don't need file descriptor for timers.
More information about the nginx-devel