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

Optimize Adaptive Server Selection #13952

Merged
merged 12 commits into from
Sep 12, 2024
Merged

Conversation

praveenc7
Copy link
Contributor

@praveenc7 praveenc7 commented Sep 8, 2024

Summary

This PR enhances the server selection logic in the adaptive server selector by using a HashMap for efficient server rank lookups and a HashSet to track selected servers. These changes improve performance when processing large sets of segments and servers, resulting in faster and more scalable server selection.
Screenshot 2024-09-09 at 1 31 26 PM

Description

The existing implementation of the adaptive server selector uses a linear search on a list (serverRankList) to determine server rankings, leading to performance inefficiencies when handling large numbers of servers

  • The serverRankMap is now used for ranking lookups, providing O(1) access to server ranks compared to the previous O(n) list iteration.
  • A HashSet (selectedServers) is introduced to track which servers have been selected and use it exit early

Complexity:
Total complexity of the adaptive server selection process per segment is reduced to O(m) per segment (with m being the number of candidates), improving the overall process to O(n * m) for n segments.

Previous: O(n* m * s) (with s being the number of total servers).

@praveenc7 praveenc7 changed the title Improve time complexity for adaptiveServerSelector Optimize Adaptive Server Selection Sep 8, 2024
Copy link
Contributor

@vvivekiyer vvivekiyer left a comment

Choose a reason for hiding this comment

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

Please attach the CPU flame graph where we saw the increased CPU utilization.
Also would be good to post the before vs after CPU utilization.

@praveenc7 praveenc7 marked this pull request as ready for review September 9, 2024 20:30
@codecov-commenter
Copy link

codecov-commenter commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 57.92%. Comparing base (59551e4) to head (dad3a28).
Report is 1020 commits behind head on master.

Files with missing lines Patch % Lines
...instanceselector/ReplicaGroupInstanceSelector.java 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #13952      +/-   ##
============================================
- Coverage     61.75%   57.92%   -3.83%     
- Complexity      207      219      +12     
============================================
  Files          2436     2612     +176     
  Lines        133233   143201    +9968     
  Branches      20636    21985    +1349     
============================================
+ Hits          82274    82953     +679     
- Misses        44911    53752    +8841     
- Partials       6048     6496     +448     
Flag Coverage Δ
custom-integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration <0.01% <0.00%> (-0.01%) ⬇️
integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration2 0.00% <0.00%> (ø)
java-11 57.89% <92.85%> (-3.82%) ⬇️
java-21 57.80% <92.85%> (-3.83%) ⬇️
skip-bytebuffers-false 57.91% <92.85%> (-3.84%) ⬇️
skip-bytebuffers-true 57.76% <92.85%> (+30.03%) ⬆️
temurin 57.92% <92.85%> (-3.83%) ⬇️
unittests 57.92% <92.85%> (-3.83%) ⬇️
unittests1 40.74% <ø> (-6.15%) ⬇️
unittests2 27.98% <92.85%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jasperjiaguo jasperjiaguo left a comment

Choose a reason for hiding this comment

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

lgtm otherwise, linter is failing, could you please fix?

Copy link
Contributor

@vvivekiyer vvivekiyer left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for this optimization.

Copy link
Contributor

@jasperjiaguo jasperjiaguo left a comment

Choose a reason for hiding this comment

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

minor. Thanks for the optimizations

@jasperjiaguo jasperjiaguo merged commit 604b244 into apache:master Sep 12, 2024
21 checks passed
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