You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/03/31 16:43:21 UTC

[GitHub] [beam] kennknowles commented on a change in pull request #14197: [BEAM-11945] Add debug capture to SDK harness

kennknowles commented on a change in pull request #14197:
URL: https://github.com/apache/beam/pull/14197#discussion_r605056458



##########
File path: sdks/java/harness/src/main/java/org/apache/beam/fn/harness/status/MemoryMonitor.java
##########
@@ -0,0 +1,342 @@
+/*
+ * 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.fn.harness.status;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayDeque;
+import java.util.Queue;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.AtomicDouble;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A runnable which monitors a server for GC thrashing.
+ *
+ * <p>Note: Only one instance of this should be initialized per server and it should be done when
+ * the server starts running.
+ *
+ * <p>This runnable works as follows:
+ *
+ * <ul>
+ *   <li>It wakes up periodically and determines how much time was spend on garbage collection since
+ *       the last time it woke up.
+ *   <li>If the time spent in garbage collection in the last period of time exceeds a certain
+ *       threshold, that period is marked as "being in GC thrashing"
+ *   <li>It keeps track of the GC thrashing status of the last few periods.
+ *   <li>Every time the runnable's thread wakes up, it computes the ratio {@code (# monitored
+ *       periods in GC thrashing) / (# monitored periods)}.
+ *   <li>If this ratio exceeds a certain threshold, it is assumed that the server is in GC
+ *       thrashing.
+ * </ul>
+ */
+public class MemoryMonitor implements Runnable {

Review comment:
       +1 to parity where it makes sense, but forking is just fine. Definitely remove anything Dataflow-specific from the SDK harness.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org