gpt4 book ai didi

erlang:start_timer/3 vs 计时器:send_after/3

转载 作者:行者123 更新时间:2023-12-04 13:09:39 24 4
gpt4 key购买 nike

我应该更喜欢什么:

erlang:start_timer(Ttl, self(), time_to_die)

或者
timer:send_after(Ttl, self(), {timeout, time_to_die})

如果我的用例是将单个原子消息发送到 gen_server?我希望有数十万个 gen_servers,并且每一个都需要有一个关联的 TTL 计时器事件。

最佳答案

Common Caveats section of the Erlang Efficiency Guide说:

Creating timers using erlang:send_after/3 and erlang:start_timer/3 is much more efficient than using the timers provided by the timer module. The timer 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 as timer:tc/3 or timer:sleep/1), do not call the timer-server process and are therefore harmless.

关于erlang:start_timer/3 vs 计时器:send_after/3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11626199/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com