srowen closed pull request #23401: [SPARK-26513][Core] : Trigger GC on executor 
node idle
URL: https://github.com/apache/spark/pull/23401
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/scala/org/apache/spark/executor/Executor.scala 
b/core/src/main/scala/org/apache/spark/executor/Executor.scala
index a30a501e5d4a1..311c89de8afe7 100644
--- a/core/src/main/scala/org/apache/spark/executor/Executor.scala
+++ b/core/src/main/scala/org/apache/spark/executor/Executor.scala
@@ -370,6 +370,8 @@ private[spark] class Executor(
       val threadMXBean = ManagementFactory.getThreadMXBean
       val taskMemoryManager = new TaskMemoryManager(env.memoryManager, taskId)
       val deserializeStartTime = System.currentTimeMillis()
+      val idleGCEnabled = 
conf.getBoolean("spark.executor.memory.idleGCEnabled", false)
+      val idleGCThreshold = 
conf.getDouble("spark.executor.memory.idleGCThreshold", 0.70)
       val deserializeStartCpuTime = if 
(threadMXBean.isCurrentThreadCpuTimeSupported) {
         threadMXBean.getCurrentThreadCpuTime
       } else 0L
@@ -628,6 +630,22 @@ private[spark] class Executor(
           }
       } finally {
         runningTasks.remove(taskId)
+        if(idleGCEnabled) {
+          if (runningTasks.isEmpty) {
+            triggerGCOnIdle(idleGCThreshold)
+          }
+        }
+      }
+    }
+
+    /**
+     * Trigger GC on executor wait for remaining tasks to finish.
+     */
+    private def triggerGCOnIdle(threshold: Double): Unit = {
+      val memoryMXBean = ManagementFactory.getMemoryMXBean
+      if (memoryMXBean.getHeapMemoryUsage.getUsed >
+        threshold * memoryMXBean.getHeapMemoryUsage.getMax) {
+        memoryMXBean.gc()
       }
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to