POE::Resource::Clock is a helper module for POE::Kernel. It provides the features to keep an internal
monotonic clock and a wall clock. It also converts between this monotonic clock and the wall clock.
The monotonic clock is used to keep an ordered queue of events. The wall clock is used to communicate
the time with user code ("alarm_set" in POE::Kernel, "alarm_remove" in POE::Kernel).
There are 3 possible clock sources in order of preference: POSIX::RT::Clock, Time::HiRes and "time" in
perlfunc. Only "POSIX::RT::Clock" has a separate monotonic and wall clock; the other two use the same
source for both clocks.
Clock selection and behaviour is controlled with the following:
USE_POSIXRT
export POE_USE_POSIXRT=0
or
sub POE::Kernel::USE_POSIXRT { 0 }
Uses the "monotonic" clock source for queue priority and the "realtime" clock source for wall clock. Not
used if POSIX::RT::Clock is not installed or your system does not have a "monotonic" clock.
Defaults to true. If you want the old POE behaviour, set this to 0.
USE_STATIC_EPOCH
export POE_USE_STATIC_EPOCH=0
or
sub POE::Kernel::USE_STATIC_EPOCH { 0 }
The epoch of the POSIX::RT::Clock monotonic is different from that of the realtime clock. For instance
on Linux 2.6.18, the monotonic clock is the number of seconds since system boot. This epoch is used to
convert from walltime into monotonic time for "alarm" in POE::Kernel, "alarm_add" in POE::Kernel and
"alarm_set" in POE::Kernel. If "USE_STATIC_EPOCH" is true (the default), then the epoch is calculated at
load time. If false, the epoch is calculated each time it is needed.
Defaults to true. Only relevant for if using POSIX::RT::Clock. Long-running POE servers should have this
set to false so that system clock skew does mess up the queue.
It is important to point out that without a static epoch, the ordering of the following two alarms is
undefined.
$poe_kernel->alarm_set( a1 => $time );
$poe_kernel->alarm_set( a2 => $time );
USE_EXACT_EPOCH
export POE_USE_EXACT_EPOCH=1
or
sub POE::Kernel::USE_EXACT_EPOCH { 1 }
There currently no way to exactly get the monotonic clock's epoch. Instead the difference between the
current monotonic clock value to the realtime clock's value is used. This is obviously inexact because
there is a slight delay between the 2 system calls. Setting USE_EXACT_EPOCH to true will calculate an
average of this difference over 250 ms or at least 20 samples. What's more, the system calls are done in
both orders (monotonic then realtime, realtime then monotonic) to try and get a more exact value.
Defaults to false. Only relevant if "USE_STATIC_EPOCH" is true.
USE_HIRES
export POE_USE_HIRES=0
or
sub POE::Kernel::USE_HIRES { 0 }
Use Time::HiRes as both monotonic and wall clock source. This was POE's previous default clock.
Defaults to true. Only relevant if "USE_POSIXRT" is false. Set this to false to use "time" in perlfunc.