wangshengjie123 commented on code in PR #2061:
URL: 
https://github.com/apache/incubator-celeborn/pull/2061#discussion_r1396654752


##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -2835,6 +2850,75 @@ object CelebornConf extends Logging {
       .longConf
       .createOptional
 
+  val WORKER_JVM_QUAKE_ENABLED: ConfigEntry[Boolean] =
+    buildConf("celeborn.worker.jvm.quake.enabled")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("When true, Celeborn worker will start the jvm quake to monitor of 
gc behavior, " +
+        "which enables early detection of memory management issues and 
facilitates fast failure.")
+      .booleanConf
+      .createWithDefault(false)
+
+  val WORKER_JVM_QUAKE_CHECK_INTERVAL: ConfigEntry[Long] =
+    buildConf("celeborn.worker.jvm.quake.check.interval")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("Interval of gc behavior checking for worker jvm quake.")
+      .timeConf(TimeUnit.MILLISECONDS)
+      .createWithDefaultString("1s")
+
+  val WORKER_JVM_QUAKE_RUNTIME_WEIGHT: ConfigEntry[Double] =
+    buildConf("celeborn.worker.jvm.quake.runtime.weight")
+      .categories("worker")
+      .version("0.3.2")
+      .doc(
+        "The factor by which to multiply running JVM time, when weighing it 
against GCing time. " +
+          "\"Deficit\" is accumulated as gc_time - runtime * runtime_weight, 
and is compared against threshold " +
+          "to determine whether to take action.")
+      .doubleConf
+      .createWithDefault(5)
+
+  val WORKER_JVM_QUAKE_DUMP_THRESHOLD: ConfigEntry[Long] =
+    buildConf("celeborn.worker.jvm.quake.dump.threshold")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("The threshold of heap dump for the maximum GC \"deficit\" which 
can be accumulated before jvmquake takes action.")
+      .timeConf(TimeUnit.MILLISECONDS)
+      .createWithDefaultString("30s")
+
+  val WORKER_JVM_QUAKE_KILL_THRESHOLD: ConfigEntry[Long] =
+    buildConf("celeborn.worker.jvm.quake.kill.threshold")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("The threshold of system kill for the maximum GC \"deficit\" which 
can be accumulated before jvmquake takes action.")
+      .timeConf(TimeUnit.MILLISECONDS)
+      .createWithDefaultString("60s")
+
+  val WORKER_JVM_QUAKE_DUMP_ENABLED: ConfigEntry[Boolean] =
+    buildConf("celeborn.worker.jvm.quake.dump.enabled")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("Whether to heap dump for the maximum GC \"deficit\" during worker 
jvm quake.")
+      .booleanConf
+      .createWithDefault(true)
+
+  val WORKER_JVM_QUAKE_DUMP_PATH: OptionalConfigEntry[String] =
+    buildConf("celeborn.worker.jvm.quake.dump.path")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("The path of heap dump for the maximum GC \"deficit\" during worker 
jvm quake, " +
+        "which default value is 
[java.io.tmpdir]/celeborn/jvm-quake/dump/[pid].")

Review Comment:
   with default value?



##########
worker/src/main/scala/org/apache/celeborn/service/deploy/worker/monitor/JVMQuake.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.celeborn.service.deploy.worker.monitor
+
+import java.io.File
+import java.lang.management.ManagementFactory
+import java.nio.file.Files
+import java.util.concurrent.{ScheduledExecutorService, TimeUnit}
+
+import com.google.common.annotations.VisibleForTesting
+import com.sun.management.HotSpotDiagnosticMXBean
+import org.apache.commons.io.FileUtils
+import sun.jvmstat.monitor._
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.{ThreadUtils, Utils}
+
+/**
+ * The JVM quake provides granular monitoring of GC behavior, which enables 
early detection of memory management
+ * issues and facilitates fast failure.
+ *
+ * Note: The principle is in alignment with GC instability detection algorithm 
for jvmquake project of Netflix:
+ * https://github.com/Netflix-Skunkworks/jvmquake.
+ *
+ * @param conf Celeborn configuration with jvm quake config.
+ */
+class JVMQuake(conf: CelebornConf) extends Logging {
+
+  import JVMQuake._
+
+  val dumpFile = "worker-quake-heapdump.hprof"
+  var heapDumped: Boolean = false
+
+  private[this] val enabled = conf.workerJvmQuakeEnabled
+  private[this] val checkInterval = conf.workerJvmQuakeCheckInterval
+  private[this] val runtimeWeight = conf.workerJvmQuakeRuntimeWeight
+  private[this] val dumpThreshold = conf.workerJvmQuakeDumpThreshold.toNanos
+  private[this] val killThreshold = conf.workerJvmQuakeKillThreshold.toNanos
+  private[this] val dumpEnabled = conf.workerJvmQuakeDumpEnabled
+  private[this] val dumpPath = conf.workerJvmQuakeDumpPath
+  private[this] val exitCode = conf.workerJvmQuakeExitCode
+  private[this] val dumpDir =
+    
s"${Utils.createDirectory(FileUtils.getTempDirectoryPath).getPath}/jvm-quake/dump"
+
+  private[this] var lastExitTime: Long = 0L
+  private[this] var lastGCTime: Long = 0L
+  private[this] var bucket: Long = 0L
+  private[this] var scheduler: ScheduledExecutorService = _
+
+  def start(): Unit = {
+    if (enabled) {
+      lastExitTime = getLastExitTime
+      lastGCTime = getLastGCTime
+      scheduler = 
ThreadUtils.newDaemonSingleThreadScheduledExecutor("jvm-quake")
+      scheduler.scheduleWithFixedDelay(
+        new Runnable() {
+          override def run(): Unit = {
+            JVMQuake.this.run()
+          }
+        },
+        0,
+        checkInterval,
+        TimeUnit.MILLISECONDS)
+    }
+  }
+
+  def stop(): Unit = {
+    if (enabled) {
+      scheduler.shutdown()
+    }
+  }
+
+  private def run(): Unit = {
+    val currentExitTime = getLastExitTime
+    val currentGCTime = getLastGCTime
+    val gcTime = currentGCTime - lastGCTime
+    val runTime = currentExitTime - lastExitTime - gcTime
+
+    bucket = Math.max(0, bucket + gcTime - BigDecimal(runTime * 
runtimeWeight).toLong)
+    logDebug(s"Time: (gc time: $gcTime, execution time: $runTime)")
+    logDebug(
+      s"Capacity: (bucket: $bucket,  dump threshold: $dumpThreshold, kill 
threshold: $killThreshold)")
+
+    if (bucket > dumpThreshold) {
+      logError(s"JVM GC has reached the threshold: bucket: $bucket, 
dumpThreshold: $dumpThreshold.")
+      if (shouldHeapDump) {
+        val savePath = getHeapDumpSavePath
+        val linkPath = getHeapDumpLinkPath
+        heapDump(savePath, linkPath)
+      } else if (bucket > killThreshold) {
+        System.exit(exitCode)
+      }
+    }
+    lastExitTime = currentExitTime
+    lastGCTime = currentGCTime
+  }
+
+  def shouldHeapDump: Boolean = {
+    dumpEnabled && !heapDumped
+  }
+
+  @VisibleForTesting
+  def getHeapDumpSavePath: String =
+    dumpPath.getOrElse(s"$dumpDir/$getProcessId/hprof")

Review Comment:
   with config default value is better



##########
worker/src/main/scala/org/apache/celeborn/service/deploy/worker/monitor/JVMQuake.scala:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.celeborn.service.deploy.worker.monitor
+
+import java.io.File
+import java.lang.management.ManagementFactory
+import java.nio.file.Files
+import java.util.concurrent.{ScheduledExecutorService, TimeUnit}
+
+import com.google.common.annotations.VisibleForTesting
+import com.sun.management.HotSpotDiagnosticMXBean
+import org.apache.commons.io.FileUtils
+import sun.jvmstat.monitor._
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.{ThreadUtils, Utils}
+
+/**
+ * The JVM quake provides granular monitoring of GC behavior, which enables 
early detection of memory management
+ * issues and facilitates fast failure.
+ *
+ * Note: The principle is in alignment with GC instability detection algorithm 
for jvmquake project of Netflix:
+ * https://github.com/Netflix-Skunkworks/jvmquake.
+ *
+ * @param conf Celeborn configuration with jvm quake config.
+ */
+class JVMQuake(conf: CelebornConf) extends Logging {
+
+  import JVMQuake._
+
+  val dumpFile = "worker-quake-heapdump.hprof"

Review Comment:
   If worker restart, heapdump may exists, add worker identifer seems better, 
like host-port.



##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -2835,6 +2850,75 @@ object CelebornConf extends Logging {
       .longConf
       .createOptional
 
+  val WORKER_JVM_QUAKE_ENABLED: ConfigEntry[Boolean] =
+    buildConf("celeborn.worker.jvm.quake.enabled")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("When true, Celeborn worker will start the jvm quake to monitor of 
gc behavior, " +
+        "which enables early detection of memory management issues and 
facilitates fast failure.")
+      .booleanConf
+      .createWithDefault(false)
+
+  val WORKER_JVM_QUAKE_CHECK_INTERVAL: ConfigEntry[Long] =
+    buildConf("celeborn.worker.jvm.quake.check.interval")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("Interval of gc behavior checking for worker jvm quake.")
+      .timeConf(TimeUnit.MILLISECONDS)
+      .createWithDefaultString("1s")
+
+  val WORKER_JVM_QUAKE_RUNTIME_WEIGHT: ConfigEntry[Double] =
+    buildConf("celeborn.worker.jvm.quake.runtime.weight")
+      .categories("worker")
+      .version("0.3.2")
+      .doc(
+        "The factor by which to multiply running JVM time, when weighing it 
against GCing time. " +
+          "\"Deficit\" is accumulated as gc_time - runtime * runtime_weight, 
and is compared against threshold " +
+          "to determine whether to take action.")
+      .doubleConf
+      .createWithDefault(5)
+
+  val WORKER_JVM_QUAKE_DUMP_THRESHOLD: ConfigEntry[Long] =
+    buildConf("celeborn.worker.jvm.quake.dump.threshold")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("The threshold of heap dump for the maximum GC \"deficit\" which 
can be accumulated before jvmquake takes action.")
+      .timeConf(TimeUnit.MILLISECONDS)
+      .createWithDefaultString("30s")
+
+  val WORKER_JVM_QUAKE_KILL_THRESHOLD: ConfigEntry[Long] =
+    buildConf("celeborn.worker.jvm.quake.kill.threshold")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("The threshold of system kill for the maximum GC \"deficit\" which 
can be accumulated before jvmquake takes action.")
+      .timeConf(TimeUnit.MILLISECONDS)
+      .createWithDefaultString("60s")
+
+  val WORKER_JVM_QUAKE_DUMP_ENABLED: ConfigEntry[Boolean] =
+    buildConf("celeborn.worker.jvm.quake.dump.enabled")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("Whether to heap dump for the maximum GC \"deficit\" during worker 
jvm quake.")
+      .booleanConf
+      .createWithDefault(true)
+
+  val WORKER_JVM_QUAKE_DUMP_PATH: OptionalConfigEntry[String] =
+    buildConf("celeborn.worker.jvm.quake.dump.path")
+      .categories("worker")
+      .version("0.3.2")
+      .doc("The path of heap dump for the maximum GC \"deficit\" during worker 
jvm quake, " +
+        "which default value is 
[java.io.tmpdir]/celeborn/jvm-quake/dump/[pid].")

Review Comment:
   with default value?



##########
worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Worker.scala:
##########
@@ -271,6 +272,9 @@ private[celeborn] class Worker(
   private val userResourceConsumptions =
     JavaUtils.newConcurrentHashMap[UserIdentifier, (ResourceConsumption, 
Long)]()
 
+  private val jvmQuake = JVMQuake.create(conf)

Review Comment:
   `celeborn.worker.jvm.quake.enabled` to avoid initialize JVMQuake



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