Skip to content
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

Replace PSQ timer queue with a timer wheel #84

Merged
merged 8 commits into from May 7, 2023
Merged

Replace PSQ timer queue with a timer wheel #84

merged 8 commits into from May 7, 2023

Conversation

wingo
Copy link
Owner

@wingo wingo commented May 2, 2023

This PR adds a timer wheel, like https://www.snellman.net/blog/archive/2016-07-27-ratas-hierarchical-timer-wheel/. I ported it from https://github.com/snabbco/snabb/blob/master/src/lib/fibers/timer.lua, which I also wrote. It seems to increase the number of threads that can (sleep 1) concurrently by about a factor of 15 or so. WDYT @aconchillo ?

wingo added 8 commits May 2, 2023 13:54
* fibers/timer-wheel.scm: New file.
* Makefile.am (SOURCES): Add to build.
* fibers/scheduler.scm (<scheduler>): A scheduler's timers is no longer
a functional priority queue, but rather a timer wheel.  This should
decrease overhead.

There is one open question about ordering within a tick; you create a
wheel with a particular precision, and it will choose a precision at
least that precise (and no more than twice as precise).  Within a tick,
however, events are unordered.  Does it matter?  We can add a sort phase
here, perhaps when inserting the events.
Now that sleeping is cheaper, we can have more parallel sleepers.
@aconchillo
Copy link
Collaborator

HI! I just read the article (very nice!) and kind of followed the implementation. This is great. Please, merge!

@wingo wingo merged commit 83712f6 into master May 7, 2023
4 checks passed
wip-sync pushed a commit to NetBSD/pkgsrc-wip that referenced this pull request Jun 1, 2023
packaging changes: NetBSD fixes are now upstream

fibers 1.3.1 -- 2023-05-30
==========================

* Fix posix-clocks-darwin usage of extension library.

fibers 1.3.0 -- 2023-05-29
==========================

* Replace PSQ timer queue with new timer wheel.
  (see wingo/fibers#84)

* Fix libevent cross-compilation issues.

* Always define (getaffinity) and (setaffinity) if not found.

* Rename 'scm_pipe2' to 'scm_fibers_pipe2' to fix a build error with Guile
  3.0.9.

* Fix bit-vector deprecation warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants