Discussion:
libevent timer triggering early
(too old to reply)
Elanchezhiyan Elango
2014-05-12 07:39:20 UTC
Permalink
Raw Message
I have an application that uses libevent timers to trigger periodic
database operations.

Following is the general overview of how the timer is used.
1. A timer is set to trigger at a specific time.
2. The process continues to run other operations.
3. The timer triggers at the right time, does DB operations, sets the timer
to triggered after a specific number of seconds (within the next 5 minutes).
4. The process continues to run other operations.
5. The timer triggers but earlier than the number of seconds set in step 3.

The first few timer triggers look correct. After that initially the timer
seems to trigger only a few seconds earlier than the number of seconds set
in step 3. But it keeps getting worse. It looks like the magnitude of error
in how early the timer is triggered depends on the length of DB operations
done inside the timer's event handler function. Eventually the timer
triggers at unpredictable times and it's a mess because the DB operations
happen at weird times.

Any idea why this might be happening?

Thanks,
Elan.
Elanchezhiyan Elango
2014-05-12 07:52:06 UTC
Permalink
Raw Message
Forgot to add, I am using:

libevent 2.0.19-stable
Scientific Linux release 6.1 (Carbon)
Kernel version 2.6.32

Thanks,
Elan.
Post by Elanchezhiyan Elango
I have an application that uses libevent timers to trigger periodic
database operations.
Following is the general overview of how the timer is used.
1. A timer is set to trigger at a specific time.
2. The process continues to run other operations.
3. The timer triggers at the right time, does DB operations, sets the
timer to triggered after a specific number of seconds (within the next 5
minutes).
4. The process continues to run other operations.
5. The timer triggers but earlier than the number of seconds set in step 3.
The first few timer triggers look correct. After that initially the timer
seems to trigger only a few seconds earlier than the number of seconds set
in step 3. But it keeps getting worse. It looks like the magnitude of error
in how early the timer is triggered depends on the length of DB operations
done inside the timer's event handler function. Eventually the timer
triggers at unpredictable times and it's a mess because the DB operations
happen at weird times.
Any idea why this might be happening?
Thanks,
Elan.
Nick Mathewson
2014-05-12 15:19:04 UTC
Permalink
Raw Message
On Mon, May 12, 2014 at 3:39 AM, Elanchezhiyan Elango
I have an application that uses libevent timers to trigger periodic database
operations.
Following is the general overview of how the timer is used.
1. A timer is set to trigger at a specific time.
2. The process continues to run other operations.
3. The timer triggers at the right time, does DB operations, sets the timer
to triggered after a specific number of seconds (within the next 5 minutes).
4. The process continues to run other operations.
5. The timer triggers but earlier than the number of seconds set in step 3.
The first few timer triggers look correct. After that initially the timer
seems to trigger only a few seconds earlier than the number of seconds set
in step 3. But it keeps getting worse. It looks like the magnitude of error
in how early the timer is triggered depends on the length of DB operations
done inside the timer's event handler function. Eventually the timer
triggers at unpredictable times and it's a mess because the DB operations
happen at weird times.
Any idea why this might be happening?
Maybe the time cache is interfering with the timer? This shouldn't
happen for most asynchronous programming problems, but if the DB
operation is taking multiple seconds, you could run into trouble here.

To diagnose the problem (and possibly to solve it), try constructing
your event base with the EVENT_BASE_NO_CACHE_TIME option

best wishes,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Elanchezhiyan Elango
2014-05-12 19:14:33 UTC
Permalink
Raw Message
Hi Nick,

Thanks for the suggestion. The code I am looking at is using obsoleted
libevent functions. It's using event_init() instead of event_base_new(). Is
there some way to set the NO_CACHE_TIME option with the obsoleted functions?

Thanks,
Elan.
Post by Nick Mathewson
On Mon, May 12, 2014 at 3:39 AM, Elanchezhiyan Elango
Post by Elanchezhiyan Elango
I have an application that uses libevent timers to trigger periodic
database
Post by Elanchezhiyan Elango
operations.
Following is the general overview of how the timer is used.
1. A timer is set to trigger at a specific time.
2. The process continues to run other operations.
3. The timer triggers at the right time, does DB operations, sets the
timer
Post by Elanchezhiyan Elango
to triggered after a specific number of seconds (within the next 5
minutes).
Post by Elanchezhiyan Elango
4. The process continues to run other operations.
5. The timer triggers but earlier than the number of seconds set in step
3.
Post by Elanchezhiyan Elango
The first few timer triggers look correct. After that initially the timer
seems to trigger only a few seconds earlier than the number of seconds
set
Post by Elanchezhiyan Elango
in step 3. But it keeps getting worse. It looks like the magnitude of
error
Post by Elanchezhiyan Elango
in how early the timer is triggered depends on the length of DB
operations
Post by Elanchezhiyan Elango
done inside the timer's event handler function. Eventually the timer
triggers at unpredictable times and it's a mess because the DB operations
happen at weird times.
Any idea why this might be happening?
Maybe the time cache is interfering with the timer? This shouldn't
happen for most asynchronous programming problems, but if the DB
operation is taking multiple seconds, you could run into trouble here.
To diagnose the problem (and possibly to solve it), try constructing
your event base with the EVENT_BASE_NO_CACHE_TIME option
best wishes,
--
Nick
***********************************************************************
unsubscribe libevent-users in the body.
Loading...