Skip to content

Avoid using ConcurrentLinkedDeque.size #1038

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

Merged
merged 1 commit into from
Oct 10, 2019
Merged

Conversation

tylerbenson
Copy link
Contributor

It is a linear operation that can take a long time when many spans are involved.

Using an atomic integer to track the size allows it to be a constant operation.

It is a linear operation that can take a long time when many spans are involved.

Using an atomic integer to track the size allows it to be a constant operation.
@tylerbenson tylerbenson requested a review from a team as a code owner October 10, 2019 14:25
@Override
public int size() {
return completedSpanCount.get();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems super-hackish. This class still exposes full ConcurrentLinkedDeque API but with this change it would be somewhat broken because this counter is not completed. Also addFirst is not threadsafe.

I would suggest dropping inheritance from ConcurrentLinkedDeque to remove potential confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize it would be better to drop the inheritance, but this is a class I see us removing in the near future, so I didn't want to put the effort into improving it right now with the priority on getting a fix out asap.

Also addFirst is not threadsafe

Do you mean that it's possible for the count to not match the actual? I realize this is the case, but considering size is always "approximate" in a concurrent collection I felt it was an acceptable tradeoff.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'd agree with getting away from extendinh ConcurrentLinkedDeque or any collection for that matter.

But yes, the result of size even if accurate is potentially immediately out of date with any concurrent collection, so I think this works fine. If we don't want to change size itself, we could make a separate estimateSize routine and call that instead, but I don't feel strongly either way.

Copy link
Contributor

@randomanderson randomanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short-term, this fixes the issue. Longterm, this class has a lot more changes that are necessary.

@tylerbenson tylerbenson merged commit cfa05b0 into master Oct 10, 2019
@tylerbenson tylerbenson deleted the tyler/fix-size-operation branch October 11, 2019 09:00
@tylerbenson tylerbenson added this to the 0.34.0 milestone Oct 11, 2019
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.

4 participants