Optimize performance on DiscoveryNodeManager #18542
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Avoid unnecessary nested loops O(N*N) on DiscoveryNodeManager#refreshNodesInternal
Additional context and related issues
It does nested loop O(N*N) when services filter out failure nodes on DiscoveryNodeManager#refreshNodesInternal, it's no big deal on small clusters with few nodes, however it consumes quite a lot of cpu cycles on large cluster with over 1000 nodes, that will do 1,000,000 cycles per round of refreshNodeInternal. According to acutal cpu profiling, we found jvm does not optimize the code automatically, so this commit optimize it and avoid nested loop.
Release notes
( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text: