-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Time wheel implementation required #10
Comments
接口有点奇怪啊。不应该是类似于这种吗 interface Timer {
void runDelayed(Runnable r, long step, TimeUnit tu);
} |
不应该 |
@wkgcass 说
|
这个接口设计是有原因的。因为selector要根据最近定时任务的时间poll,还要根据是否有定时任务来决定是否永久等待。而且定时任务还可以随时取消。 |
@wkgcass 这块写的有点问题,如果差大于Integer.MAX_VALUE 2147483647就溢出了。建议改成 PriorityQueue<TimeElemImpl<T>> queue = new PriorityQueue<>(Comparator.comparingLong(elem -> elem.triggerTime)); |
我在我的branch里改吧 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
目前的定时任务是通过PriorityQueue维护的,考虑换成时间轮。
由于常见的TCP超时时间是15分钟(例如LVS),而UDP则更短,一般认为不会出现超过15分钟的定时任务
使用4层时间轮,每层32个元素。可以表示
32^4=1048576 ms > 15 minutes
。使用链表维护同一毫秒的定时任务列表。使用32是因为%
操作可以优化为&
操作不需要考虑并发,时间事件的访问总是在eventloop里面进行的。
对于超过
1048576ms
的定时任务,放在PriorityQueue中排序,当时间低于1048576 ms
时从队列中挪出来放进时间轮里。需要实现的接口:TimeQueue.java和TimeEvent.java
The text was updated successfully, but these errors were encountered: