-
Notifications
You must be signed in to change notification settings - Fork 529
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
Striped fiber callback hashtable #1913
Merged
Merged
Conversation
This file contains 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
Silly question: why not just use |
It's not a silly question. We developed this custom hashtable to be able to iterate over it without allocation of any objects, which is important when a VM error occurs, we catch it in order to notify every fiber, but during this time, the VM is in an undefined state. Is this still desirable? |
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.
Cats Effect 3
IO
has a mechanism for registering the error callback (Throwable => Unit
) of each Fiber which isunsafeRun*
. These callbacks are important for the runtime to have control over and this feature enables proper error reporting during an abrupt shutdown of theIORuntime
(usually due to unrecoverable VM errors).Up to now, we had a single thread safe hashtable which was locked exclusively by each
unsafeRun*
operation, both when starting and when ending a fiber (inserting the callback and removing it). While these locks were only meant for achieving mutual exclusion in a very tiny critical section (there is no possibility of deadlocks or anything), this is still a bottleneck in a system where a lot ofIO
s are directlyunsafeRun*
, possibly concurrently.This PR is very similar in spirit to the
ScalQueue
PR and howjava.util.concurrent.ConcurrentHashMap
works. It introduces a new internal type which conceptually represents a thread safe hashtable, but is in fact composed of many of the previously developed thread safe hashtables, and load balances between them. This way, while each subsection of the hashtable is still locked exclusively during insertion and removal, it reduces the contention on each lock because there are many more of them, instead of 1 global lock, and presumably the hashes of the callbacks are regularly distributed and map to different subsections of the whole hashtable.The code only touches internal classes and should be completely binary compatible (with added filters), but please review this carefully, I'm still new to
mima
.