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



##########
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:
       Is it worth abstracting to make it compatible since legacy worker is 
being deprecated?
   
   The head dump upload to GCS does use FileSystems, so I can add those back as 
a generic upload. Also had an offline discussion, runner v2 can handle the SDK 
harness exiting on gc thrashing, so will add that back as well
   
   cc: @robertwb, @kennknowles 




-- 
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:
[email protected]


Reply via email to