HashedWheelTimer与ScheduledThreadPoolExecutor具有更高的性能 [英] HashedWheelTimer vs ScheduledThreadPoolExecutor for higher performance

查看:1078
本文介绍了HashedWheelTimer与ScheduledThreadPoolExecutor具有更高的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您需要在一台计算机上的jvm内尽可能快地安排大量(非阻塞)任务,我正在计算要使用的计时器实现。

I'm figuring what a timer implementation to use if you need to schedule tons of (non blocking) tasks as fast as possible inside jvm on one machine.

我研究过 ScheduledThreadPoolExecutor HashedWheelTimer 来源(+轮定时器一般文档),这里是基本差异(N - 数字)到目前为止所有未完成的预定任务,C - 轮尺寸):

I've studied ScheduledThreadPoolExecutor and HashedWheelTimer sources (+wheel timer general docs) and here are basic differences (N - number of all outstanding scheduled tasks so far, C - wheel size):

ScheduledThreadPoolExecutor


  • O(log N)用于添加新任务

  • O(1)每个计时器刻度(但每个任务勾选,因此总体上为N)

  • O(日志N)取消任务

  • 锁定每个刻度/任务

  • O(log N) for adding new task
  • O(1) per each timer tick (but tick per each task, so N overall)
  • O(log N) cancelling the task
  • lock per each tick/task

HashedWheelTimer


  • O(1)添加新任务

  • 每个计时器滴答的O(m)(m~N / C,其中C> 512),所以~C整体打勾

  • O(m)取消任务

  • 锁定每桶任务(每次打勾)

  • O(1) adding new task
  • O(m) per each timer tick (m ~ N/C where C > 512 approx), so ~C ticks overall
  • O(m) for cancelling a task
  • lock per bucket of tasks (on each tick)

因此,我倾向于将硬件计时器用于这种用例,因为您必须以最小的开销快速安排任务,即新任务的O(1)。
此外,您将最小化簿记活动,因为您将获得更少的滴答数(N 在这种情况下取​​消不是非常重要的功能

Thus I tend using HW Timer for such use-case, because you must schedule tasks quickly with minimum overhead, i.e. O(1) for new task. Also you will minimize a bookkeeping activity, because you'll get less number of ticks (N < C) and less lock contention. Canceling is not very important feature in this case

是否有人尝试过这些计时器进行类似的活动以及实际看到的结果?
谢谢!

Did anybody try these timers for similar activities and what results see in practice? Thanks!

推荐答案

HWT 。除非您需要-ns-precision,否则请使用HWT。对于大多数客户端 - 服务器应用程序,HWT就足够了。在许多互联网规模的应用程序中,特别是对于超时不断变化的内存缓存,它是唯一的选择。我们在这里谈论数十亿个工作。

HWT. Unless you require to-the-ns-precision, use the HWT. For most client-server applications, a HWT is sufficient. In many internet-scale applications, especially for in-memory caches that were the timeout was constantly changing, it was the only option. We're talking about billions of jobs here.

实际上,如果你需要这种精确度,你需要一个保证中断时间而不是GC暂停的系统;即不是Java,而不是英特尔... :)

Actually, if you require that level of precision, you need a system with guaranteed interrupt times and not GC pauses; i.e. not Java, not Intel... :)

这篇关于HashedWheelTimer与ScheduledThreadPoolExecutor具有更高的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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