steveniemitz commented on a change in pull request #17151:
URL: https://github.com/apache/beam/pull/17151#discussion_r838612065



##########
File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/status/JfrzServlet.java
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.dataflow.worker.status;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.beam.runners.dataflow.worker.util.MemoryMonitor;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.io.ByteStreams;
+
+/**
+ * Respond to /jfrz with a page allowing downloading of the heap dumps.
+ *
+ * <p><b>Not actually serializable</b>. Its superclass is serializable but 
this subclass is not.
+ */
+@SuppressFBWarnings("SE_BAD_FIELD") // not serializable
+public class JfrzServlet extends BaseStatusServlet {
+
+  private final MemoryMonitor memoryMonitor;
+
+  public JfrzServlet(MemoryMonitor memoryMonitor) {
+    super("jfrz");
+    this.memoryMonitor = memoryMonitor;
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws IOException {
+    String durationStr = req.getParameter("duration");
+    Duration duration;
+    if (durationStr == null) {
+      duration = Duration.ofSeconds(60);

Review comment:
       it'll be a little tricky to plumb that through (and it could be unset in 
the PipelineOptions). Plus I think this is a reasonable default.

##########
File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/status/JfrzServlet.java
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.dataflow.worker.status;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.beam.runners.dataflow.worker.util.MemoryMonitor;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.io.ByteStreams;
+
+/**
+ * Respond to /jfrz with a page allowing downloading of the heap dumps.
+ *
+ * <p><b>Not actually serializable</b>. Its superclass is serializable but 
this subclass is not.
+ */
+@SuppressFBWarnings("SE_BAD_FIELD") // not serializable
+public class JfrzServlet extends BaseStatusServlet {
+
+  private final MemoryMonitor memoryMonitor;
+
+  public JfrzServlet(MemoryMonitor memoryMonitor) {
+    super("jfrz");
+    this.memoryMonitor = memoryMonitor;
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws IOException {
+    String durationStr = req.getParameter("duration");
+    Duration duration;
+    if (durationStr == null) {
+      duration = Duration.ofSeconds(60);
+    } else {
+      duration = Duration.parse(durationStr);
+    }
+
+    ServletOutputStream writer = resp.getOutputStream();
+    InputStream jfrStream;
+    try {
+      jfrStream = memoryMonitor.runJfrProfile(duration).get();
+    } catch (Exception e) {
+      resp.setContentType("text/html;charset=utf-8");

Review comment:
       heh honestly I just copied this from 
[HeapzServlet](https://github.com/apache/beam/blob/master/runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/status/HeapzServlet.java#L79).
  I'm happy to just let it propagate and get a 500, I think thats cleaner.

##########
File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/util/MemoryMonitor.java
##########
@@ -198,20 +208,36 @@ public long totalGCTimeMilliseconds() {
 
   private final File localDumpFolder;
 
+  private final String workerId;
+
+  private final @Nullable JfrInterop jfrInterop;
+
   public static MemoryMonitor fromOptions(PipelineOptions options) {
     DataflowPipelineDebugOptions debugOptions = 
options.as(DataflowPipelineDebugOptions.class);
+    DataflowWorkerHarnessOptions workerHarnessOptions =
+        options.as(DataflowWorkerHarnessOptions.class);
     String uploadToGCSPath = debugOptions.getSaveHeapDumpsToGcsPath();
+    String workerId = workerHarnessOptions.getWorkerId();
     boolean canDumpHeap = uploadToGCSPath != null || 
debugOptions.getDumpHeapOnOOM();
     double gcThrashingPercentagePerPeriod = 
debugOptions.getGCThrashingPercentagePerPeriod();
 
+    Duration jfrProfileDuration;
+    if (uploadToGCSPath != null && debugOptions.getRecordJfrOnGcThrashing()) {
+      jfrProfileDuration = 
Duration.ofSeconds(debugOptions.getJfrRecordingDurationSec());

Review comment:
       +1, I'll validate it in DataflowRunner too so its caught at submission 
time.

##########
File path: 
runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/util/MemoryMonitorTest.java
##########
@@ -137,9 +140,33 @@ public void uploadToGcs() throws Exception {
     assertThat(files[0].getAbsolutePath(), Matchers.containsString("hprof"));
   }
 
+  @Test
+  public void uploadJfrProfilesOnThrashing() throws Exception {
+    if (Environments.getJavaVersion() != Environments.JavaVersion.java8) {

Review comment:
       oh thats cool!

##########
File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/util/MemoryMonitor.java
##########
@@ -515,6 +562,10 @@ public void run() {
         if (isThrashing.get()) {
           currentThrashingCount++;
 
+          if (currentThrashingCount == 1) {
+            runJfrProfileOnHeapThrashing();
+          }
+

Review comment:
       sorry whats the diff here?  Was the indentation wrong?




-- 
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]


Reply via email to