scwhittle commented on code in PR #41869:
URL: https://github.com/apache/beam/pull/41869#discussion_r4767111586
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/profiler/ScopedProfiler.java:
##########
@@ -123,15 +129,55 @@ public ProfileScope emptyScope(ProfilerWrapper profiler) {
private final ProfilerWrapper profiler;
private final ProfilingState profilingState;
- public static final ScopedProfiler INSTANCE = new ScopedProfiler(new
ProfilerWrapper());
+ private static final ScopedProfiler DISABLED =
+ new ScopedProfiler(new ProfilerWrapper(),
ProfilingState.PROFILING_ABSENT);
+
+ /**
+ * Lazily initializes the JNI-backed {@link ScopedProfiler} only when
explicitly enabled via the
+ * {@link #ENABLE_SCOPED_PROFILER_EXPERIMENT} experiment.
+ */
+ private static final class EnabledScopedProfilerHolder {
+ private static final ScopedProfiler INSTANCE = new ScopedProfiler(new
ProfilerWrapper());
+ }
+
+ /**
+ * Returns a disabled {@link ScopedProfiler} that always produces {@link
NoopProfileScope#NOOP}.
+ */
+ public static ScopedProfiler disabled() {
+ return DISABLED;
+ }
+
+ /**
+ * Returns a {@link ScopedProfiler} configured according to {@code options}.
Per-step profiling is
+ * disabled by default and only enabled when the {@value
#ENABLE_SCOPED_PROFILER_EXPERIMENT}
+ * experiment is present.
+ */
+ public static ScopedProfiler fromOptions(@Nullable PipelineOptions options) {
+ if (ExperimentalOptions.hasExperiment(options,
ENABLE_SCOPED_PROFILER_EXPERIMENT)) {
+ return EnabledScopedProfilerHolder.INSTANCE;
+ }
+ return DISABLED;
+ }
+
+ @VisibleForTesting
Review Comment:
this doesn't seem particularly worthwhile method for test as it duplicates
the logic instead of actually testing the prod path.
Let's just remove this
##########
CHANGES.md:
##########
@@ -128,6 +128,7 @@
* (Python) Optimized core combiners: `ToListCombineFn` and
`ConcatListCombineFn` replace quadratic `sum(accumulators, [])` merges with
linear `itertools.chain.from_iterable` (and in-place `extend()` in
`ConcatListCombineFn.add_input`); `CountCombineFn.add_inputs` uses O(1) `len()`
for `Sized` inputs; and `TopCombineFn`/`SampleCombineFn` operate directly on
the underlying heap ([#41062](https://github.com/apache/beam/pull/41062)).
* (Python) `WriteImpl._expand_bounded` (used by bounded file sinks such as
`WriteToText`, `WriteToAvro`, `WriteToParquet`, and `WriteToTFRecord`) now
skips the redundant per-element `WindowInto(GlobalWindows())` pass when the
upstream `PCollection` already uses the default global windowing strategy
([#40911](https://github.com/apache/beam/pull/40911)).
* (Java) Added support for `--experiments=java_gc=<GC>` (`UseParallelGC`,
`UseG1GC`, or `UseZGC`; defaults to `UseParallelGC`) in the portable Java SDK
harness container, enabling alternative JVM garbage collectors on
memory-constrained workers
([#41029](https://github.com/apache/beam/pull/41029)).
+* (Java) Dataflow legacy worker: per-step Cloud Profiler sample tagging
(`ScopedProfiler`, which annotates CPU/wall samples with internal `"sN"` step
IDs via the `attr` label) is now disabled by default to avoid per-element JNI
overhead. Re-enable with `--experiments=enable_scoped_profiler` if needed for
offline `pprof` CLI inspection
([#41869](https://github.com/apache/beam/pull/41869)).
Review Comment:
These steps were not visible in Cloud Profiler but were present in
downloaded profiles. Annotating the steps can be reenabled via ... if needed.
##########
CHANGES.md:
##########
@@ -128,6 +128,7 @@
* (Python) Optimized core combiners: `ToListCombineFn` and
`ConcatListCombineFn` replace quadratic `sum(accumulators, [])` merges with
linear `itertools.chain.from_iterable` (and in-place `extend()` in
`ConcatListCombineFn.add_input`); `CountCombineFn.add_inputs` uses O(1) `len()`
for `Sized` inputs; and `TopCombineFn`/`SampleCombineFn` operate directly on
the underlying heap ([#41062](https://github.com/apache/beam/pull/41062)).
* (Python) `WriteImpl._expand_bounded` (used by bounded file sinks such as
`WriteToText`, `WriteToAvro`, `WriteToParquet`, and `WriteToTFRecord`) now
skips the redundant per-element `WindowInto(GlobalWindows())` pass when the
upstream `PCollection` already uses the default global windowing strategy
([#40911](https://github.com/apache/beam/pull/40911)).
* (Java) Added support for `--experiments=java_gc=<GC>` (`UseParallelGC`,
`UseG1GC`, or `UseZGC`; defaults to `UseParallelGC`) in the portable Java SDK
harness container, enabling alternative JVM garbage collectors on
memory-constrained workers
([#41029](https://github.com/apache/beam/pull/41029)).
+* (Java) Dataflow legacy worker: per-step Cloud Profiler sample tagging
(`ScopedProfiler`, which annotates CPU/wall samples with internal `"sN"` step
IDs via the `attr` label) is now disabled by default to avoid per-element JNI
overhead. Re-enable with `--experiments=enable_scoped_profiler` if needed for
offline `pprof` CLI inspection
([#41869](https://github.com/apache/beam/pull/41869)).
Review Comment:
use Java Streaming Runner terminology
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/profiler/ScopedProfiler.java:
##########
@@ -27,6 +30,9 @@
})
public class ScopedProfiler {
+ /** Experiment to enable per-step scoped profiling via {@link Profiler}.
Disabled by default. */
+ public static final String ENABLE_SCOPED_PROFILER_EXPERIMENT =
"enable_scoped_profiler";
Review Comment:
The scoped profiler seems more like RAII implementation detail. The feature
seems like it is more per-step profiling attribute. How about updating
experiment and other variables etc to enable_per_step_profiling_attribute
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]