Add fiber queues for execution context schedulers#15345
Merged
straight-shoota merged 15 commits intocrystal-lang:masterfrom Feb 12, 2025
Merged
Add fiber queues for execution context schedulers#15345straight-shoota merged 15 commits intocrystal-lang:masterfrom
straight-shoota merged 15 commits intocrystal-lang:masterfrom
Conversation
Simple abstraction on top of a mutex and condition variable to synchronize the execution of a set of threads.
Contributor
Isn't that a |
Contributor
|
How much of the queues will be public interface that are hard to change later on? |
Collaborator
Author
|
@BlobCodes Yes, it's a LIFO singly linked list (in contrast to the FIFO doubly linked list of @yxhuvud Good call, they should all be |
defe37d to
7c67d27
Compare
Collaborator
Author
|
Moved to |
straight-shoota
approved these changes
Feb 3, 2025
Collaborator
Author
|
The MinGW failure on CI should be fixed by #15404. |
Member
|
Hm, that'll leave MinGW broken until we merge that fixup then? 🤔 |
Collaborator
Author
|
That's possible, yes. We might want to split #15404:
|
Collaborator
Author
|
Updated to add:
Let's avoid any further changes 🤞 |
4 tasks
Collaborator
Author
|
Following the addition of Fiber::Stack in #15409, the |
bfe4756 to
edcb13f
Compare
Collaborator
Author
straight-shoota
approved these changes
Feb 11, 2025
ysbaddaden
added a commit
to ysbaddaden/crystal
that referenced
this pull request
Feb 11, 2025
ysbaddaden
added a commit
to crystal-lang/rfcs
that referenced
this pull request
Feb 25, 2025
ysbaddaden
added a commit
to ysbaddaden/crystal
that referenced
this pull request
Apr 3, 2025
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces 3 queues that will be used the ExecutionContext schedulers. They derivate from Go's internal queues (
q,runqandglobrunq).Fiber::Queue: holds an unbounded singly-linked list of Fiber with a bulk insert operation.Note: we may consider renaming
Fiber::QueueasFiber::ListandFiber#schedlinkasFiber#list_next?ExecutionContext::GlobalQueue: wraps aFiber::Queuewith optional thread-safety and a bulk grab operation. There will be a single global queue per execution context shared among one or more schedulers.The point is to have an unbounded space to store as many fibers as needed, or to store cross context enqueues —the runnables queue below only supports a single producer.
ExecutionContext::Runnables: a bounded, lock-free, chase-lev queue (single producer, multiple consumers) with bulk operations. There will be a one runnables queue per execution context scheduler (aka local queue).On overflow or underflow it pushes/grabs half the queue size to/from the global queue (locking the mutex once in a while).
Any scheduler can steal from any runnables queue in the execution context at any time, directly into their own local queue.
The point is to have a quick list to push/pop and steal from, and to limit the occurrences where we must lock the scheduler mutex to reach to the global queue.
Refs #15342