高效定时器算法 [英] Efficient Timer Algorithm
问题描述
实现简单计时器库的最佳算法是什么?该库应允许以下内容:
- 启动计时器
- 停止计时器
- 要检查计时器是否仍在运行
在计时器到期时,将调用回调函数
计时器模块将允许计时器具有Ns的时间分辨率,并且每Ns将给模块一个踢,以提示模块检查过期的计时器。 / p>
许多计时器可能同时处于活动状态。
最好的算法需要满足以下目标
- 在处理计时器到期回调时要坚决地启动/停止计时器
- 允许计时器开始,停止和停止快速检查
- 内存占用较小
问候
我看到的关于计时器的最佳算法是研究论文哈希和分层定时轮:用于高效实现计时器功能的数据结构
我知道在Java中有Netty,JBoss的实现,而且我敢肯定,如果您使用Java编写,也可以在其他地方使用。
What is the best algorithm to implement a simple timer library. The library should allow the following:
- Timers to be started
- Timers to be stopped
- Timers to be checked whether they are still running
On Timer expiry a callback function will be called.
The timer module will allow timers to have a time resolution of Ns and the module shall be given a kick every Ns to prompt the module to check for expired timers.
Many timers may be simultaneously active.
The best algorithm needs to meet the following goals
- Be Robust to timers being started / stopped while processing a timer expiry callback
- Allow timers to be started, stopped and checked quickly
- Have a small memory footprint
Regards
Best algorithm I have seen for timers is a timer wheel found in the research paper Hashed and Hierarchical Timing Wheels: Data Structures for the Efficient Implementation of a Timer Facility
I know in Java there is an implementation with Netty, JBoss and I am sure elsewhere too that you can use, if you are writing in Java.
这篇关于高效定时器算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!