Skip to content

[Dataflow] Disable per-step profiling attribute annotation by default - #41869

Merged
scwhittle merged 5 commits into
apache:masterfrom
arunpandianp:disable_scoped_profiler_experiment
Dec 2, 2026
Merged

scwhittle merged 5 commits into
apache:masterfrom
arunpandianp:disable_scoped_profiler_experiment

Conversation

@arunpandianp

@arunpandianp arunpandianp commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Disables per-step profiling attribute annotation (ScopedProfiler) by default in the Dataflow Streaming Java Runner (and legacy Java batch worker) to avoid per-element JNI overhead when Cloud Profiler is enabled. Annotating steps can be re-enabled via --experiments=enable_per_step_profiling_attribute if needed.

Core Cloud Profiler collection/uploads (enable_google_cloud_profiler) and Dataflow execution state tracking are unaffected.

Motivation

When the Google Cloud Profiler Java agent (profiler_java_agent.so) is attached, ScopedProfiler registers each step's internal NameContext.originalName() (e.g., "s1", "s2", "sN") via JNI (Profiler.registerAttribute) and invokes JNI Profiler.setAttribute in DataflowExecutionState.onActivate on every state push and pop in ExecutionStateTracker.enterState (twice per element in ParDoOperation.process, WriteOperation.process, and FlattenOperation.process, per shuffle key/value in GroupingShuffleReader, and per bundle in ReadOperation.runReadLoop). On high-throughput / high-cardinality pipelines, these per-element JNI transitions add measurable CPU overhead on the hot path.

Why this is safe to disable by default

  • ScopedProfiler only annotates CPU and wall profile samples with a raw attr label set to the internal original step name ("sN", not the user-facing transform name); heap sampling ignores it.
  • These step annotations are not visible in the Google Cloud Console Cloud Profiler UI or the Dataflow UI (Cloud Profiler UI does not display or filter/group by sample labels).
  • They are only present in downloaded raw .pb.gz profiles (or profiles saved via --saveProfilesToGcs) when inspected offline with pprof CLI tag flags (-tagfocus=attr=..., -tagroot=attr).
  • Core Cloud Profiler functionality (CPU, wall, and heap profiles, call stacks, and flame graphs) and Dataflow execution state tracking (msec counters, lull logging, side-input read counters) continue to work unchanged.
  • The Dataflow portable runner (Java sdks/java/harness, Python, and Go workers) already does not emit these attr labels.

Disable per-step profiler scope tagging in the Dataflow Java legacy
worker (`org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler`)
by default, with an opt-in experiment (`--experiments=enable_scoped_profiler`)
to re-enable it if needed.

Motivation:
When the Google Cloud Profiler Java agent (`profiler_java_agent.so`) is
attached, `ScopedProfiler` registers each step's internal
`NameContext.originalName()` (e.g., `"s1"`, `"s2"`, `"sN"`) via JNI
(`Profiler.registerAttribute`) and invokes JNI `Profiler.setAttribute`
inside `DataflowExecutionState.onActivate` on every state push and pop in
`ExecutionStateTracker.enterState` (twice per element in
`ParDoOperation.process`, `WriteOperation.process`, and
`FlattenOperation.process`, as well as per shuffle key/value in
`GroupingShuffleReader` and once per bundle in
`ReadOperation.runReadLoop`). On high-throughput / high-cardinality
pipelines, these per-element JNI transitions incur measurable CPU
overhead on the hottest execution path.

Why it is safe to disable by default:
- `ScopedProfiler` only annotates CPU and wall profile samples with a
  raw `attr` label set to the internal original step name (`"sN"`, not
  the user-facing transform name). Heap sampling ignores this attribute.
- The exported `"sN"` `attr` label is not user-visible in the Google
  Cloud Console Cloud Profiler UI or the Dataflow UI (Cloud Profiler UI
  does not display or support filtering/grouping by sample labels).
- The only way to inspect or use the `"sN"` `attr` label is by
  downloading raw `.pb.gz` pprof profiles (or saving profiles to GCS via
  `--saveProfilesToGcs`) and manually passing tag flags to the `pprof`
  CLI (e.g., `-tagfocus=attr=...`, `-tagroot=attr`), then correlating
  `"sN"` back to the user transform name.
- Core Cloud Profiler functionality (CPU, wall, and heap profile
  collection and upload via `enable_google_cloud_profiler`, call stacks,
  and flame graphs) continues to work unchanged.
- Dataflow execution state tracking (msec counters, lull logging, and
  side-input read counters) is completely unaffected.
- Dataflow Runner v2 (`sdks/java/harness`), Python, and Go workers
  already do not use `ScopedProfiler` or export `attr` labels.

Changes:
- Gate `ScopedProfiler` behind `--experiments=enable_scoped_profiler`
  via `ScopedProfiler.fromOptions(PipelineOptions)` and
  `ScopedProfiler.disabled()`, lazily probing JNI only when enabled so
  disabled workers never call `Profiler.getAttribute()` or instantiate
  `TaggedProfileScope` (allowing `NoopProfileScope.NOOP` to remain
  monomorphic for JIT inlining).
- Keep `Profiler.java` and its JNI native method declarations untouched.
- Derive `ScopedProfiler` from `PipelineOptions` in
  `DataflowExecutionStateTracker` and pass it from
  `DataflowExecutionContext` to `DataflowOperationContext`, and use
  `ScopedProfiler.fromOptions(options).emptyScope()` for the `"other"`
  state in `BatchModeExecutionContext` and
  `ComputationWorkExecutorFactory`.
- Add unit tests in `ScopedProfilerTest` and `DataflowOperationContextTest`.
- Add a release note entry in `CHANGES.md`.
…er_experiment

# Conflicts:
#	CHANGES.md
#	runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/DataflowOperationContextTest.java
@arunpandianp

Copy link
Copy Markdown
Contributor Author

R: @scwhittle @kennknowles

@github-actions github-actions Bot added the size/m M: 50-249 lines changed label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This PR disables ScopedProfiler per-step JNI sample tagging in the Dataflow Java legacy worker by default to eliminate per-element JNI overhead during execution state transitions, while providing an opt-in --experiments=enable_scoped_profiler flag to re-enable it. The implementation cleanly threads ScopedProfiler through DataflowExecutionStateTracker, DataflowExecutionContext, and DataflowOperationContext with thorough unit test coverage.

🔍 General Feedback

  • The lazy initialization pattern (EnabledScopedProfilerHolder) and default DISABLED singleton in ScopedProfiler effectively avoid unnecessary JNI calls when the experiment is not enabled.
  • One minor placeholder link in CHANGES.md should be updated before merging.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

Comment thread CHANGES.md Resolved
@arunpandianp arunpandianp changed the title [Dataflow] Disable scoped profiler experiment [Dataflow] Disable scoped profiler Dec 2, 2026

@scwhittle scwhittle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FYI @reuvenlax who has been looking into beam runner performance

Comment thread CHANGES.md Resolved
Comment thread CHANGES.md Resolved
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.88%. Comparing base (f3763f8) to head (2468edc).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #41869   +/-   ##
=========================================
  Coverage     58.88%   58.88%           
- Complexity     2334     2336    +2     
=========================================
  Files          1136     1136           
  Lines        171035   171043    +8     
  Branches       1552     1552           
=========================================
+ Hits         100711   100720    +9     
  Misses        67767    67767           
+ Partials       2557     2556    -1     
Flag Coverage Δ
java 76.52% <100.00%> (+0.01%) ⬆️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… CHANGES.md

- Rename experiment and related symbols/Javadocs from enable_scoped_profiler to enable_per_step_profiling_attribute (ENABLE_PER_STEP_PROFILING_ATTRIBUTE_EXPERIMENT).
- Remove @VisibleForTesting two-argument ScopedProfiler.fromOptions(options, wrapper) and test the production fromOptions(PipelineOptions) path directly in ScopedProfilerTest.
- Update CHANGES.md to refer to Dataflow Streaming Java Runner and clarify that step annotations were not visible in Cloud Profiler, only present in downloaded profiles, and can be re-enabled via --experiments=enable_per_step_profiling_attribute.
@arunpandianp arunpandianp changed the title [Dataflow] Disable scoped profiler [Dataflow] Disable per-step profiling attribute annotation by default Dec 2, 2026
…edProfilerTest

- Remove the 5-arg DataflowOperationContext constructor overload and update its 2 test callers (TestOperationContext and DataflowOperationContextTest).
- Drop the redundant scopedProfiler field and null check in DataflowExecutionContext by typing executionStateTracker as DataflowExecutionStateTracker.
- Simplify ScopedProfilerTest to keep only disabled-by-default and enabled-with-experiment tests, and remove the redundant disabledScopedProfilerUsesNoopProfileScope test.
@scwhittle
scwhittle merged commit 3b166fb into apache:master Dec 2, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dataflow runners size/m M: 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants