yoock commented on code in PR #6572: URL: https://github.com/apache/kyuubi/pull/6572#discussion_r1699728884
########## extensions/spark/kyuubi-spark-jvm-quake/src/main/scala/org/apache/spark/kyuubi/jvm/quake/KyuubiJVMQuake.scala: ########## @@ -0,0 +1,147 @@ +/* + * 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.spark.kyuubi.jvm.quake + +import java.io.File +import java.lang.management.ManagementFactory +import java.util.concurrent.{ScheduledExecutorService, TimeUnit} + +import scala.collection.JavaConverters._ + +import KyuubiJVMQuake._ +import com.sun.management.HotSpotDiagnosticMXBean +import org.apache.spark.SparkConf +import org.apache.spark.internal.Logging +import org.apache.spark.kyuubi.jvm.quake.KyuubiConf._ +import org.apache.spark.util.ThreadUtils + +class KyuubiJVMQuake(conf: SparkConf, heapDumpEnabled: Boolean) extends Logging { + private val appId = conf.get("spark.app.id", "app-id").stripPrefix("application_") + private val dumpThreshold = TimeUnit.SECONDS.toNanos(conf.get(JVM_QUAKE_DUMP_THRESHOLD)) + private val killThreshold = TimeUnit.SECONDS.toNanos(conf.get(JVM_QUAKE_KILL_THRESHOLD)) + private val exitCode = conf.get(JVM_QUAKE_EXIT_CODE) + private val checkInterval = TimeUnit.SECONDS.toMillis(conf.get(JVM_QUAKE_CHECK_INTERVAL)) + private val runTimeWeight = conf.get(JVM_QUAKE_RUN_TIME_WEIGHT) + private[quake] val heapPath = s"${conf.get(JVM_QUAKE_HEAP_DUMP_PATH)}/$appId" + + private[quake] var (lastExitTime, lastGCTime) = getLastGCInfo + private[quake] var bucket: Long = 0L + private[quake] var heapExist: Boolean = false + + private val scheduler: ScheduledExecutorService = + ThreadUtils.newDaemonSingleThreadScheduledExecutor("jvm-quake") + + private[quake] def run(): Unit = { + val (currentExitTime, currentGcTime) = getLastGCInfo + if (currentExitTime == lastExitTime) { + return + } + val gcTime = currentGcTime - lastGCTime + val runTime = currentExitTime - lastExitTime - gcTime + + bucket = Math.max(0, bucket + gcTime - BigDecimal(runTime * runTimeWeight).toLong) + + if (bucket > dumpThreshold) { + logError(s"JVM GC has reached the threshold!!!" + + s" (bucket: ${bucket / 1000000000}s, dumpThreshold: ${dumpThreshold / 1000000000}s)") + if (shouldDumpHeap) { + saveHeap(heapPath) Review Comment: Except for the long dump time, there are no other abnormalities -- 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: notifications-unsubscr...@kyuubi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@kyuubi.apache.org For additional commands, e-mail: notifications-h...@kyuubi.apache.org