-
Notifications
You must be signed in to change notification settings - Fork 275
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
Lock-free WaitList #113
base: develop
Are you sure you want to change the base?
Lock-free WaitList #113
Conversation
# Conflicts: # core/include/userver/engine/impl/wait_list_fwd.hpp # core/src/engine/impl/wait_list_light.cpp # core/src/engine/impl/wait_list_light.hpp # core/src/engine/io/fd_control.cpp # core/src/engine/single_consumer_event.cpp # core/src/engine/task/task_context.cpp # core/src/engine/task/task_context.hpp
# Conflicts: # core/src/engine/impl/wait_list_light.cpp
CLA Assistant Lite bot: I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/ 1 out of 2 committers have signed the CLA. |
const TaggedPtr<Node> null_node(kNullNode, segment_epoch); | ||
|
||
// The paper advises randomized iteration order for better performance under | ||
// contention, but we trade it for better single-threaded performance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This confuses me
My understanding is that the paper is basically "Split everything in chunks of size K, randomize iteration over chunks and hope for the best", but that "randomize and hope" part is missing - don't we just have a lock-free queue that is exactly K times slower for even single-threaded performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though the randomization is used mostly to reduce contention, it helps (it does, right?) with this loop not being O(k^2)
As of now it seems to me that we got the worst of both worlds - contention isn't reduced, complexity is O(k^2).
I propose either
- generating some (or even all, with K = 8 there are about 40k of them) possible permutations at compilation and selecting the permutation decently fast somehow or
- doing some bits manipulations here to find a candidate slot in O(1)
First way should reduce contention and might be fast enough anyway, second way should be the fastest one in single-threaded performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same applies to DoTryPopStep
context->Wakeup(impl::TaskContext::WakeupSource::kWaitList, | ||
impl::TaskContext::NoEpoch{}); | ||
void WaitList::WakeupAll() noexcept { | ||
while (impl_->WakeupOne()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random thought: this could potentially be optimized using enqueue_bulk interface of moodycamel
No description provided.