Repository navigation
[Dataflow] Disable per-step profiling attribute annotation by default - #41869
Conversation
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
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
There was a problem hiding this comment.
📋 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 defaultDISABLEDsingleton inScopedProfilereffectively avoid unnecessary JNI calls when the experiment is not enabled. - One minor placeholder link in
CHANGES.mdshould be updated before merging.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
scwhittle
left a comment
There was a problem hiding this comment.
FYI @reuvenlax who has been looking into beam runner performance
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… 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.
…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.
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_attributeif 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,ScopedProfilerregisters each step's internalNameContext.originalName()(e.g.,"s1","s2","sN") via JNI (Profiler.registerAttribute) and invokes JNIProfiler.setAttributeinDataflowExecutionState.onActivateon every state push and pop inExecutionStateTracker.enterState(twice per element inParDoOperation.process,WriteOperation.process, andFlattenOperation.process, per shuffle key/value inGroupingShuffleReader, and per bundle inReadOperation.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
ScopedProfileronly annotates CPU and wall profile samples with a rawattrlabel set to the internal original step name ("sN", not the user-facing transform name); heap sampling ignores it..pb.gzprofiles (or profiles saved via--saveProfilesToGcs) when inspected offline withpprofCLI tag flags (-tagfocus=attr=...,-tagroot=attr).sdks/java/harness, Python, and Go workers) already does not emit theseattrlabels.