What should I prefer:
erlang:start_timer(Ttl, self(), time_to_die)
or
timer:send_after(Ttl, self(), {timeout, time_to_die})
if my use case is to send a single atom message to a gen_server? I expect to have hundreds of thousands of gen_servers and each one of those will need to have an associated TTL timer event.
The Common Caveats section of the Erlang Efficiency Guide says:
Creating timers using
erlang:send_after/3
anderlang:start_timer/3
is much more efficient than using the timers provided by thetimer
module. Thetimer
module uses a separate process to manage the timers, and that process can easily become overloaded if many processes create and cancel timers frequently (especially when using the SMP emulator).The functions in the
timer
module that do not manage timers (such astimer:tc/3
ortimer:sleep/1
), do not call the timer-server process and are therefore harmless.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With