[erlang-questions] Optmized way to handle more timers

Jesper Louis Andersen <>
Tue Mar 15 18:55:00 CET 2011

On Tue, Mar 15, 2011 at 17:09, maruthavanan s
<> wrote:

> I have a situation where my task can fail and I have to retry it after n seconds. The situation there may be around 100 timers in a second at the worst case. I feel creating 100 timers for this situation is not optimum.
> Any ideas how to handle this.

With timers? :)

I'd use erlang:send_after/2 or erlang:start_timer/2 to install timers.
It is quite much faster than the timer module and it should easily be
able to cope with many simultaneous timers. You can also cancel timers
again when you know they are not necessary anymore, but do use the
TimerRef to make sure you don't handle old stray timers. If you are
using gen_fsm's, then they have their own timers which may come in
handy for you.


More information about the erlang-questions mailing list