[erlang-questions] Erlang Scheduler for Recurring Events

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Aug 25 13:27:59 CEST 2011


On Wed, Aug 24, 2011 at 13:51, Hank Knight <hknight555@REDACTED> wrote:
> Hello,
>
> I need to scheduler a number of recurring events using Erlang.  Some
> events need to be triggered every second, some every three seconds and
> some every minute.  Any simple advise on how to do this or what tools
> to do?

My solution would be to use erlang:send_after(..) to set up a timer
and then set the timer again whenever it triggers. The "timer" module
is also there, but it is considerably less effective if you end up
with many timers (according to the performance guide -
http://www.erlang.org/doc/efficiency_guide/commoncaveats.html#id58959).

If you have lots and lots of these timers, and your naive approach
hits performance problems, then perhaps a trick from operating system
kernels can be tried. The idea is that you lag the timer. Rather than
waiting exactly three seconds, you wait 3 seconds or more, until the
next time slot trigger for the event. That means a 3 sec timer takes
somewhere between 3 and 6 seconds and a 1 minute timer takes between 1
and 2 minutes. It allows you to bundle up large number of events on
the same timer, which could be faster in some situations.

On the other hand, Erlangs internal timer stuff is pretty fast
already, so only begin playing with it when the basic implementation
can't cope.
-- 
J.



More information about the erlang-questions mailing list