Erlang:很多计时器好吗?

时间:2016-11-05 04:53:36

标签: timer erlang match

我有一个gen_server进程维护一个池,对于每个传入的请求,我需要检查池以查看该传入请求是否匹配,如果有,则从池中删除匹配的请求对这两项请求作出答复;如果没有,则将新请求放入池中供以后检查。

如果请求RT秒内没有匹配,我需要回复R来回复public String toString() { String formatOutput = " "; for (int i = 0; i < daysLeftRental.length; i++) { formatOutput = formatOutput + "\nLocker " + i + ": " + (daysLeftRental[i] == -1 ? "Available" : daysLeftRental[i].toString()); } return formatOutput; } 。 #34;我找不到你的匹配&#34;。

理想情况下,我希望使用计时器执行此操作,特别是对于每个传入请求,如果没有匹配,请像以前一样将其放入池中,但也启动计时器以告知gen_server如果时间到了则将其删除当然,如果以后匹配,应取消计时器。

我担心的是,如果池中有很多不匹配的请求,那么会有很多运行的计时器,这会(太多的计时器)成为问题吗?

1 个答案:

答案 0 :(得分:5)

R18中的计时器实施有了很大的改进。

    Besides the API changes and time warp modes a lot of
    scalability and performance improvements regarding time
    management has been made internally in the runtime system.
    Examples of such improvements are scheduler specific timer
    wheels, scheduler specific BIF timer management, parallel
    retrieval of monotonic time and system time on systems with
    primitives that are not buggy.

调度程序特定的计时器轮正是您的场景中的有趣内容。我怀疑你会在Erlang或任何其他语言/环境中找到更好的解决方案。因此,当您使用R18或更新时,您的解决方案应该没问题。