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

Lock-free WaitList #113

Draft
wants to merge 89 commits into
base: develop
Choose a base branch
from

Conversation

Anton3
Copy link
Member

@Anton3 Anton3 commented Sep 8, 2022

No description provided.

@github-actions
Copy link

github-actions bot commented Sep 8, 2022

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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.
@Anton3
@segoon
You can retrigger this bot by commenting recheck in this Pull Request

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.
Copy link
Contributor

@itrofimow itrofimow Sep 8, 2022

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?

Copy link
Contributor

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

  1. 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
  2. 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

Copy link
Contributor

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()) {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants