Skip to content

Avoid some uses of ConcurrentLinkedQueue.size() in SharedBlobCacheService #128119

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 6 commits into from
May 20, 2025

Conversation

cbuescher
Copy link
Member

SharedBlobCacheService keeps track of the free regions in a ConcurrentLinkedQueue. We use its "size()" method in three places outside of tests but unfortunately this is not a constant time operation because of the asynchronous nature of this queue. This change removes two of the uses where we only check if the queue is empty by calling the "isEmpty()" method instead.

SharedBlobCacheService keeps track of the free regions in a
ConcurrentLinkedQueue. We use its "size()" method in three places
outside of tests but unfortunately this is not a constant time operation
because of the asynchronous nature of this queue. This change removes
two of the uses where we only check if the queue is empty by calling the
"isEmpty()" method instead.
@cbuescher cbuescher added :Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. v9.1.0 labels May 18, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-indexing (Team:Distributed Indexing)

@elasticsearchmachine elasticsearchmachine added the Team:Distributed Indexing Meta label for Distributed Indexing team label May 18, 2025
@cbuescher
Copy link
Member Author

Fyi, this came up while profiling a new use of "maybeFetchRange" in ESS where we saw a majority of the call was used by calling "SharedBlobCacheService#freeRegionCount"
Screenshot 2025-04-30 at 11 46 30

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticsearchmachine
Copy link
Collaborator

Hi @cbuescher, I've created a changelog YAML for you.

@cbuescher
Copy link
Member Author

@elasticmachine update branch

@elasticmachine
Copy link
Collaborator

There are no new commits on the base branch.

Copy link
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

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

Great catch Christoph ! 🚀

Should we also add a warning for the freeRegionCount method not being constant time? Either javadoc or @Deprecated or both?

@cbuescher
Copy link
Member Author

Should we also add a warning for the freeRegionCount method not being constant time?

Good call, the method is already package private and from the current doc comment should have been only used by tests. I'll remove that doc and make it even clearer that this isn't constant-time.

@cbuescher cbuescher merged commit 4c0c9b6 into elastic:main May 20, 2025
17 checks passed
@cbuescher
Copy link
Member Author

@tlrx Andrei just made a good point about whether it makes sense to backport this change to 9.0 and 8.19. If you don't disagree for some reason I would do that later today. Let me know if you think otherwise.

@tlrx
Copy link
Member

tlrx commented May 20, 2025

All good for me to backport.

cbuescher added a commit to cbuescher/elasticsearch that referenced this pull request May 20, 2025
…vice (elastic#128119)

SharedBlobCacheService keeps track of the free regions in a
ConcurrentLinkedQueue. We use its "size()" method in three places
outside of tests but unfortunately this is not a constant time operation
because of the asynchronous nature of this queue. This change removes
two of the uses where we only check if the queue is empty by calling the
"isEmpty()" method instead.
@cbuescher
Copy link
Member Author

Backport PR to 9.0 and 8.19: #128194

elasticsearchmachine pushed a commit that referenced this pull request May 20, 2025
…vice (#128119) (#128194)

SharedBlobCacheService keeps track of the free regions in a
ConcurrentLinkedQueue. We use its "size()" method in three places
outside of tests but unfortunately this is not a constant time operation
because of the asynchronous nature of this queue. This change removes
two of the uses where we only check if the queue is empty by calling the
"isEmpty()" method instead.
cbuescher added a commit to cbuescher/elasticsearch that referenced this pull request May 20, 2025
…vice (elastic#128119) (elastic#128194)

SharedBlobCacheService keeps track of the free regions in a
ConcurrentLinkedQueue. We use its "size()" method in three places
outside of tests but unfortunately this is not a constant time operation
because of the asynchronous nature of this queue. This change removes
two of the uses where we only check if the queue is empty by calling the
"isEmpty()" method instead.
elasticsearchmachine pushed a commit that referenced this pull request May 20, 2025
…vice (#128119) (#128194) (#128203)

SharedBlobCacheService keeps track of the free regions in a
ConcurrentLinkedQueue. We use its "size()" method in three places
outside of tests but unfortunately this is not a constant time operation
because of the asynchronous nature of this queue. This change removes
two of the uses where we only check if the queue is empty by calling the
"isEmpty()" method instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. >non-issue Team:Distributed Indexing Meta label for Distributed Indexing team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants