Skip to content

Conversation

@vrajat
Copy link
Contributor

@vrajat vrajat commented Sep 9, 2024

The PR add the following improvements to OOM protection for Multi-Stage Engine.

Add a config parameter to turn off sampling for MSE

pinot.query.scheduler.accounting.enable.thread.sampling.mse.debug
Since the feature is new, a debug config has been added to turn off sampling for MSE when there are mixed workloads.

As part of this change, a new fn Tracing::sampleMSE has been added to not add an if condition in the sampling path. The sample function is in the critical path wrt performance and SSE will not be affected by the extra check.

Assign query id to workers

Worker threads are not assigned query ids. Refer:

Tracing.getThreadAccountant().createExecutionContext(null, taskId, taskType, threadExecutionContext);

Therefore, the resource used by these threads was not attributed to a query. Now, if there is a parentContext available, the query id is set. During aggregation, memory used by workers is also added to a query's aggregate statistics.

  String queryId = null;
      if (threadExecutionContext != null) {
        queryId = threadExecutionContext.getQueryId();
      } else {
        LOGGER.warn("Request ID not available. ParentContext not set for query worker thread.");
      }
      Tracing.getThreadAccountant()
          .createExecutionContext(queryId, taskId, taskType, threadExecutionContext);
    }

Instrument threads for Leaf Stage Operator.

Threads that executed Leaf Stage operators in MSE were not tracked. Now runners and workers are instrumented correctly.

Fix annotations

Nullable/NotNull annotations have been added. The most important is CPUMemThreadLevelAccountingObjects.::setThreadTaskStatus . Tracing::setupWorker can pass null for queryId.

tags: bugfix

@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 43.33333% with 17 lines in your changes missing coverage. Please review.

Project coverage is 57.89%. Comparing base (59551e4) to head (9118e0c).
Report is 1099 commits behind head on master.

Files with missing lines Patch % Lines
.../main/java/org/apache/pinot/spi/trace/Tracing.java 0.00% 10 Missing ⚠️
...re/accounting/PerQueryCPUMemAccountantFactory.java 50.00% 6 Missing ⚠️
...va/org/apache/pinot/spi/utils/CommonConstants.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #13955      +/-   ##
============================================
- Coverage     61.75%   57.89%   -3.87%     
- Complexity      207      219      +12     
============================================
  Files          2436     2612     +176     
  Lines        133233   143221    +9988     
  Branches      20636    21988    +1352     
============================================
+ Hits          82274    82912     +638     
- Misses        44911    53829    +8918     
- Partials       6048     6480     +432     
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.87% <43.33%> (-3.84%) ⬇️
java-21 57.78% <43.33%> (-3.85%) ⬇️
skip-bytebuffers-false 57.88% <43.33%> (-3.86%) ⬇️
skip-bytebuffers-true 57.76% <43.33%> (+30.03%) ⬆️
temurin 57.89% <43.33%> (-3.87%) ⬇️
unittests 57.88% <43.33%> (-3.87%) ⬇️
unittests1 40.77% <43.33%> (-6.12%) ⬇️
unittests2 27.92% <0.00%> (+0.19%) ⬆️

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.

@vrajat vrajat changed the title Fixes in accounting memory usage in multi-stage queries Fixes for Multi-Stage Queries Memory Accounting Sep 10, 2024
@vrajat vrajat marked this pull request as ready for review September 10, 2024 12:58
@vrajat vrajat changed the title Fixes for Multi-Stage Queries Memory Accounting Improvements to OOM protection for Multi-Stage Engine Sep 10, 2024
@vrajat
Copy link
Contributor Author

vrajat commented Sep 10, 2024

Test failures are unrelated

@yashmayya yashmayya added multi-stage Related to the multi-stage query engine Configuration Config changes (addition/deletion/change in behavior) labels Sep 10, 2024
@gortiz gortiz added the bugfix label Sep 11, 2024
_isThreadSamplingEnabledForMSE =
config.getProperty(CommonConstants.Accounting.CONFIG_OF_ENABLE_THREAD_SAMPLING_MSE,
CommonConstants.Accounting.DEFAULT_ENABLE_THREAD_SAMPLING_MSE);
LOGGER.info("_isThreadSamplingEnabledForMSE: {}", _isThreadSamplingEnabledForMSE);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think using the attribute name is a good idea. Specially in case it changes in the future. Instead something like: Thread sampling enabled for MSE: true/false

@gortiz gortiz merged commit 75b7b6f into apache:master Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Configuration Config changes (addition/deletion/change in behavior) multi-stage Related to the multi-stage query engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants