高效定时器算法 [英] Efficient Timer Algorithm

查看:166
本文介绍了高效定时器算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实现简单计时器库的最佳算法是什么?该库应允许以下内容:


  1. 启动计时器

  2. 停止计时器

  3. 要检查计时器是否仍在运行

在计时器到期时,将调用回调函数



计时器模块将允许计时器具有Ns的时间分辨率,并且每Ns将给模块一个踢,以提示模块检查过期的计时器。 / p>

许多计时器可能同时处于活动状态。



最好的算法需要满足以下目标


  1. 在处理计时器到期回调时要坚决地启动/停止计时器

  2. 允许计时器开始,停止和停止快速检查

  3. 内存占用较小

问候

解决方案

我看到的关于计时器的最佳算法是研究论文哈希和分层定时轮:用于高效实现计时器功能的数据结构



我知道在Java中有Netty,JBoss的实现,而且我敢肯定,如果您使用Java编写,也可以在其他地方使用。


What is the best algorithm to implement a simple timer library. The library should allow the following:

  1. Timers to be started
  2. Timers to be stopped
  3. 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

  1. Be Robust to timers being started / stopped while processing a timer expiry callback
  2. Allow timers to be started, stopped and checked quickly
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆