Re: nginx timer in log module

2016-09-17 Thread Maxim Dounin
Hello!

On Sat, Sep 17, 2016 at 02:42:25PM +0800, 洪志道 wrote:

> Thank you for your reply, I get it now.
> 
> In other case such as I showed above, it seems we needn't do like the
> following ?
> 
>  if (ev->timer_set) {
>   ngx_del_timer(ev);
> }

Yes, as long as the code is in the timer handler it is not needed.  
Timers are called only once and they are always deleted before a 
timer handler is called.

-- 
Maxim Dounin
http://nginx.org/

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Re: nginx timer in log module

2016-09-16 Thread 洪志道
Thank you for your reply, I get it now.

In other case such as I showed above, it seems we needn't do like the
following ?

 if (ev->timer_set) {
  ngx_del_timer(ev);
}

2016-09-17 10:48 GMT+08:00 Maxim Dounin :

> Hello!
>
> On Sat, Sep 17, 2016 at 08:25:54AM +0800, 洪志道 wrote:
>
> [...]
>
> > static void
> > ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log)
> > {
> > ...
> > if (buffer->event && buffer->event->timer_set) {
> > ngx_del_timer(buffer->event);
> > }
> > }
> >
> >
> > I find there are two functions explicitly call event handler.
> > 1. ngx_event_cancel_timers happened as long as worker process quits.
> > 2. ngx_event_expire_timers in ngx_process_events_and_timers.
> >
> > And they remove timer from timer rbtree, then set timer_set zero.
> > After that they call event->handler.
> >
> > So why we call ngx_del_timer in ngx_http_log_flush again?
>
> The ngx_http_log_flush() function is also used as a flush handler
> for the log file, notably called while reopening logs.  In this
> case the timer can be set when ngx_http_log_flush() is called and
> should be deleted - and this is what the code in question does.
>
> --
> Maxim Dounin
> http://nginx.org/
>
> ___
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Re: nginx timer in log module

2016-09-16 Thread Maxim Dounin
Hello!

On Sat, Sep 17, 2016 at 08:25:54AM +0800, 洪志道 wrote:

[...]

> static void
> ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log)
> {
> ...
> if (buffer->event && buffer->event->timer_set) {
> ngx_del_timer(buffer->event);
> }
> }
> 
> 
> I find there are two functions explicitly call event handler.
> 1. ngx_event_cancel_timers happened as long as worker process quits.
> 2. ngx_event_expire_timers in ngx_process_events_and_timers.
> 
> And they remove timer from timer rbtree, then set timer_set zero.
> After that they call event->handler.
> 
> So why we call ngx_del_timer in ngx_http_log_flush again?

The ngx_http_log_flush() function is also used as a flush handler 
for the log file, notably called while reopening logs.  In this 
case the timer can be set when ngx_http_log_flush() is called and 
should be deleted - and this is what the code in question does.

-- 
Maxim Dounin
http://nginx.org/

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Re: nginx timer in log module

2016-09-16 Thread 洪志道
Well, I get it.

By the way, If I want to add a timer, it can do something like crontab in
worker process.
For example, we collect data in worker process and dump the data every 5
minutes.

event->cancelable = 1;

In event handler, the codes like the following:

static void
ngx_http_test_timer_handler(ngx_event_t *ev)
{

 if (event->timedout) {
 /* todo timedout */
 return;
 }

 if (ngx_terminate || ngx_exiting) {
 /* I'm not sure whether we need to determine the condition */
 }

 /* I think we needn't to explicitly remove the event timer */
 #if 0
 if (ev->timer_set) {
ngx_del_timer(ev);
}
#endif
}

Thanks again.

B.R.~

2016-09-17 8:25 GMT+08:00 洪志道 :

> Hi
>
> As the following codes.
>
>
> buffer->event->handler = ngx_http_log_flush_handler;
>
>
> static void
> ngx_http_log_flush_handler(ngx_event_t *ev)
> {
> ...
> if (ev->timedout) {
> ngx_http_log_flush(ev->data, ev->log);
> return;
> }
> ...
> }
>
>
> static void
> ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log)
> {
> ...
> if (buffer->event && buffer->event->timer_set) {
> ngx_del_timer(buffer->event);
> }
> }
>
>
> I find there are two functions explicitly call event handler.
> 1. ngx_event_cancel_timers happened as long as worker process quits.
> 2. ngx_event_expire_timers in ngx_process_events_and_timers.
>
> And they remove timer from timer rbtree, then set timer_set zero.
> After that they call event->handler.
>
> So why we call ngx_del_timer in ngx_http_log_flush again?
>
> Thanks.
>
> B.R~
>
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

nginx timer in log module

2016-09-16 Thread 洪志道
Hi

As the following codes.


buffer->event->handler = ngx_http_log_flush_handler;


static void
ngx_http_log_flush_handler(ngx_event_t *ev)
{
...
if (ev->timedout) {
ngx_http_log_flush(ev->data, ev->log);
return;
}
...
}


static void
ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log)
{
...
if (buffer->event && buffer->event->timer_set) {
ngx_del_timer(buffer->event);
}
}


I find there are two functions explicitly call event handler.
1. ngx_event_cancel_timers happened as long as worker process quits.
2. ngx_event_expire_timers in ngx_process_events_and_timers.

And they remove timer from timer rbtree, then set timer_set zero.
After that they call event->handler.

So why we call ngx_del_timer in ngx_http_log_flush again?

Thanks.

B.R~
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel