Skip to content

Force all FieldCaps response handling onto a single thread per request #120863

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 7 commits into from
Apr 24, 2025

Conversation

original-brownbear
Copy link
Member

@original-brownbear original-brownbear commented Jan 25, 2025

The current implementation uses a task per response model. This is unnecessarily costly when all results are merged into a single synchronized map. The concurrency across requests allows for concurrent deserialization of responses (this advantage of running on multiple threads would effectively disappear with #120010) but becomes incredibly costly when responses collide because of the hot lock acquisitions.
Also, deserializing more than a single response at a time comes with higher than necessary heap overheads (especially for the remote cluster use-case) because we hold multiple responses on-heap and deserialized but merging is sequential in the end anyways.
Also, removing all synchronization from the hot loops just outright reduces their cost even in the uncontended case.

The current implementation uses a task per response model. This is unnecessarily
costly when all results are merged into a single synchronzied map.
The concurrency across requests allows for concurrent deserialization of responses
but becomes incredibly costly when responses collide because of the hot lock
acquisitions.
Also, deserializing more than a single response at a time comes with higher than necessary
heap overheads (especially for the remote cluster use-case) because we hold multiple
responses on-heap and deserialized but merging is sequential in the end anyways.
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Jan 25, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

Copy link
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

LGTM.

This change will queue handling of the responses, and process them one at a time (rather than concurrently). I guess this could slow things a little in some cases, but that is the desired outcome to avoid unnecessary concurrency and resource utilisation in many cases.

@original-brownbear
Copy link
Member Author

Thanks Chris! In my benchmarking via the many_shards run I couldn't really make out any slowdown.
You're right that in theory we lose the concurrent deserialization of the responses but also the actual merging gets visibly cheaper by avoiding synchronization (could have also started doing the synchronization more cleverly as an alternative but the memory issues this solves and the lack of benchmarking showing a possible win out of doing that made me not look into that). In my benchmarking I couldn't actually reprodue any slowdown but I bet one can be crafted depending on the hardware + mappings but probably not a huge one.

That said my hope/assumption is that doing something like #120010 we could actually get a serious speedup out of single-threadedness and a smaller working set :) 🤞

@original-brownbear
Copy link
Member Author

Thanks Chris!

@original-brownbear original-brownbear merged commit f4a6d18 into elastic:main Apr 24, 2025
17 checks passed
@original-brownbear original-brownbear deleted the faster-field-caps branch April 24, 2025 00:06
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Apr 24, 2025
Same reasoning as for field_caps in elastic#120863,
no need to have multiple threads contending the same mutex(s) when the heavy lifting
step in handling the results is sequential anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport pending >non-issue :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants