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

[Enhancement] merge fragment-profile just in time #51001

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

murphyatwork
Copy link
Contributor

@murphyatwork murphyatwork commented Sep 12, 2024

Why I'm doing:

Currently the query profile is generated in a hierarchy way:

  • Each backend would report the profiles in fragment instance level
  • FE would maintain all these profiles in memory before query finish
  • As a result, with more fragments, more backends, this running profile would take more memory
  • For a large-size cluster, this query profile can easily take hundreds MBs of FE memory

The tradeoff:

  1. If we want to provide running profile: you have to maintain all instance profiles for running instances
  2. If we don't need it, we only need to maintain the fragment-level, then consolidate them into a query profile when finish

What I'm doing:

Merge the instance-level profile into fragment-level after it finishes:

  1. The correctness is based on that the counters would never change after it finishes
  2. It can greatly reduce memory consumption for a large-size cluster

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@murphyatwork murphyatwork requested a review from a team as a code owner September 12, 2024 11:29
@github-actions github-actions bot added the 3.3 label Sep 13, 2024
@murphyatwork murphyatwork force-pushed the murphy_opt_fragment_profile branch 2 times, most recently from d4789ca to 443638e Compare September 14, 2024 05:31
@murphyatwork murphyatwork changed the title [Enhancement] reduce runtime profile memory via merging fragment profile [Enhancement] merge fragment-profile just in time Sep 14, 2024
if (params.isSetProfile() && params.isDone()) {
int fragmentIndex = execState.getFragmentIndex();
RuntimeProfile fragmentProfile = mergedFragmentProfiles.get(fragmentIndex);
fragmentProfile.merge(params.profile);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this thread-safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@murphyatwork murphyatwork force-pushed the murphy_opt_fragment_profile branch 5 times, most recently from 91583b0 to 5feb28a Compare September 25, 2024 04:16
@murphyatwork murphyatwork enabled auto-merge (squash) October 18, 2024 02:05
Seaven
Seaven previously approved these changes Oct 18, 2024
}
}

// Remove counters from this fragment-profile
Copy link
Contributor

Choose a reason for hiding this comment

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

so after merge one instance profile into fragment profile, you actually merged counter and remove counters from instance profile, leave others same as before, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. add a purgeInstanceRunningProfile to clarify this process

@@ -337,6 +344,15 @@ public void updateProfile(FragmentInstanceExecState execState, TReportExecStatus
saveRunningProfile(profilingPlan, profile);
LOG.debug("update profile, profilingPlan: {}, profile: {}", profilingPlan, profile);
}

// Merge it into fragment-profile if this instance already finished
if (params.isSetProfile() && params.isDone()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so without consider runtime profile uploading, before this pr, every fragment instance profile will keep until merged by profile-worker thread. after this pr, fragment instance profile's counters will merged into fragment immediately in here. If some instance profile upload very slow or profile-worker is super busy, then your pr will help to reduce memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

change the strategy to handle this case: once a fragment-instance finish, purse that profile and merge it into fragment-profile, it can reduce memory

@before-Sunrise
Copy link
Contributor

suggest to add a fe config, so if anything goes wong, we can set it as false

Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Copy link

sonarcloud bot commented Oct 18, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
4.7% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 219 / 259 (84.56%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/qe/StmtExecutor.java 0 6 00.00% [951, 952, 953, 954, 955, 956]
🔵 com/starrocks/qe/scheduler/dag/FragmentInstanceExecState.java 3 12 25.00% [319, 320, 321, 322, 323, 325, 326, 327, 331]
🔵 com/starrocks/qe/scheduler/QueryRuntimeProfile.java 6 18 33.33% [318, 319, 320, 321, 322, 323, 435, 436, 442, 443, 444, 445]
🔵 com/starrocks/qe/DefaultCoordinator.java 3 4 75.00% [1040]
🔵 com/starrocks/common/profile/Counter.java 53 60 88.33% [69, 70, 73, 74, 92, 93, 192]
🔵 com/starrocks/common/util/RuntimeProfile.java 127 132 96.21% [149, 157, 161, 316, 364]
🔵 com/starrocks/common/Config.java 1 1 100.00% []
🔵 com/starrocks/common/profile/SummarizationCounter.java 26 26 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants