You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/03/15 14:06:20 UTC

[GitHub] [spark] Ngone51 opened a new pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Ngone51 opened a new pull request #31839:
URL: https://github.com/apache/spark/pull/31839


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   This PR proposes an alternative way to fix the memory leak of `ExecutionListenerBus`, which would automatically clean them up.
   
   Basically, the idea is to add `registerSparkListenerForCleanup` to `ContextCleaner`, so we can remove the `ExecutionListenerBus` from `LiveListenerBus` when the `SparkSession` is GC'ed.
   
   On the other hand, to make the `SparkSession` GC-able, we need to get rid of the reference of `SparkSession` in `ExecutionListenerBus`. Therefore, we introduced the `sessionUUID`, which is a unique identifier for SparkSession, to replace the  `SparkSession` object.
   
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   Fix the memory leak caused by `ExecutionListenerBus` mentioned in SPARK-34087.
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   Yes, save memory for users.
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   
   Added a unit test.
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801157109


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136167/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801157109


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136167/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799944708


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40673/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r595681661



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,37 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {
+    val spark = SparkSession.builder()
+      .master("local")
+      .getOrCreate()
+
+    def listenersNum(): Int = {
+      spark.sparkContext
+        .listenerBus
+        .listeners
+        .asScala
+        .count(_.isInstanceOf[ExecutionListenerBus])
+    }
+
+    (1 to 10).foreach { _ =>
+      spark.cloneSession()
+      SparkSession.clearActiveSession()
+    }
+
+    var num = listenersNum()
+    // Before GC, the number of ExecutionListenerBus is (1 + 10)
+    assert(num === 11)

Review comment:
       let's remove this line then.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801175175


   Sure, I'd like to have a try after tests pass.


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799944680


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40673/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799928463


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136089/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799557956


    Nice fix! How about adding a test case for this? (the test in "manual test" seems fine)


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r596063103



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,36 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {
+    val spark = SparkSession.builder()
+      .master("local")
+      .getOrCreate()
+
+    def listenersNum(): Int = {
+      spark.sparkContext
+        .listenerBus
+        .listeners
+        .asScala
+        .count(_.isInstanceOf[ExecutionListenerBus])
+    }
+
+    (1 to 10).foreach { _ =>
+      spark.cloneSession()
+      SparkSession.clearActiveSession()
+    }
+
+    var num = listenersNum()

Review comment:
       we can move it inside `eventually {...}` and inline it
   ```
   eventually ... {
     ...
     assert(listenersNum() < 11)
   }
   ```




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799941322


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40673/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-800819675


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40723/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799566257


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136070/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594897153



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,37 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {
+    val spark = SparkSession.builder()
+      .master("local")
+      .getOrCreate()
+
+    def listenersNum(): Int = {
+      spark.sparkContext
+        .listenerBus
+        .listeners
+        .asScala
+        .count(_.isInstanceOf[ExecutionListenerBus])
+    }
+
+    (1 to 10).foreach { _ =>
+      spark.cloneSession()
+      SparkSession.clearActiveSession()
+    }
+
+    var num = listenersNum()
+    // Before GC, the number of ExecutionListenerBus is (1 + 10)
+    assert(num === 11)
+    eventually(timeout(10.seconds), interval(1.seconds)) {
+      System.gc()
+      num = listenersNum()
+      // After GC, the number of ExecutionListenerBus should be less than 11
+      // Since GC can't 100% guarantee all out-of-referenced objects be cleaned at one time,
+      // here, we check at least one listener is cleaned up to prove the mechanism works.
+      assert(num < 11)

Review comment:
       We actually create 11 sessions: original one and 10 cloned.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r595681418



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala
##########
@@ -76,7 +76,11 @@ trait QueryExecutionListener {
 class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
   extends Logging {
 
-  private val listenerBus = new ExecutionListenerBus(session)
+  private val listenerBus = new ExecutionListenerBus(session.sessionUUID)
+  session.sparkContext.listenerBus.addToSharedQueue(listenerBus)
+  session.sparkContext.cleaner.foreach { cleaner =>

Review comment:
       Let's mention it in the PR description to be clear.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-800819675


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40723/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594897279



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,37 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {
+    val spark = SparkSession.builder()
+      .master("local")
+      .getOrCreate()
+
+    def listenersNum(): Int = {
+      spark.sparkContext
+        .listenerBus
+        .listeners
+        .asScala
+        .count(_.isInstanceOf[ExecutionListenerBus])
+    }
+
+    (1 to 10).foreach { _ =>
+      spark.cloneSession()
+      SparkSession.clearActiveSession()
+    }
+
+    var num = listenersNum()
+    // Before GC, the number of ExecutionListenerBus is (1 + 10)
+    assert(num === 11)

Review comment:
       make sense




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594868894



##########
File path: core/src/main/scala/org/apache/spark/ContextCleaner.scala
##########
@@ -276,6 +287,16 @@ private[spark] class ContextCleaner(
     }
   }
 
+  def doCleanSparkListener(listener: SparkListener): Unit = {
+    try {
+      logDebug(s"Cleaning Spark listener $listener")

Review comment:
       Does logging `$listener` show meaningful message? It is not like other cases like clean up RDD (rdd id), or clean up broadcast (broadcast id).




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801599130


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40769/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801614119


   Merged to master.
   
   @Ngone51 it has a conflict with branch-3.1. Would you mind creating a PR to backport?


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801599130


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40769/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801582271


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136187/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799472595


   The overall approach LGTM


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801566439


   retest this please


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r595655573



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala
##########
@@ -76,7 +76,11 @@ trait QueryExecutionListener {
 class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
   extends Logging {
 
-  private val listenerBus = new ExecutionListenerBus(session)
+  private val listenerBus = new ExecutionListenerBus(session.sessionUUID)
+  session.sparkContext.listenerBus.addToSharedQueue(listenerBus)
+  session.sparkContext.cleaner.foreach { cleaner =>

Review comment:
       > But, this doesn't fix memory leaks at all if spark.cleaner.referenceTracking=false technically, does it? 
   
   Yes, it doesn't.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594885074



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,37 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {

Review comment:
       how long does this test take?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594392276



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala
##########
@@ -102,6 +103,8 @@ class SparkSession private(
         new SparkSessionExtensions), Map.empty)
   }
 
+  val sessionUUID: String = UUID.randomUUID.toString

Review comment:
       shall we mark it as `private[sql]` if we don't want to expose it as a public API?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594413472



##########
File path: core/src/test/scala/org/apache/spark/ContextCleanerSuite.scala
##########
@@ -31,6 +31,7 @@ import org.scalatest.time.SpanSugar._
 import org.apache.spark.internal.{config, Logging}
 import org.apache.spark.internal.config._
 import org.apache.spark.rdd.{RDD, ReliableRDDCheckpointData}
+import org.apache.spark.scheduler.SparkListener

Review comment:
       unnecessary change




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594561487



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala
##########
@@ -76,7 +76,11 @@ trait QueryExecutionListener {
 class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
   extends Logging {
 
-  private val listenerBus = new ExecutionListenerBus(session)
+  private val listenerBus = new ExecutionListenerBus(session.sessionUUID)
+  session.sparkContext.listenerBus.addToSharedQueue(listenerBus)
+  session.sparkContext.cleaner.foreach { cleaner =>

Review comment:
       So, this fix is designed to be disabled when `spark.cleaner.referenceTracking=false`?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799532610


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40653/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799566257


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136070/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799485521






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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594396949



##########
File path: core/src/main/scala/org/apache/spark/ContextCleaner.scala
##########
@@ -293,4 +314,5 @@ private[spark] trait CleanerListener {
   def broadcastCleaned(broadcastId: Long): Unit
   def accumCleaned(accId: Long): Unit
   def checkpointCleaned(rddId: Long): Unit
+  def listenerCleaned(listener: SparkListener): Unit

Review comment:
       The session id doesn't have a 1:1 relationship with the listener so I don't think we should use the session id.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594885011



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,37 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {
+    val spark = SparkSession.builder()
+      .master("local")
+      .getOrCreate()
+
+    def listenersNum(): Int = {
+      spark.sparkContext
+        .listenerBus
+        .listeners
+        .asScala
+        .count(_.isInstanceOf[ExecutionListenerBus])
+    }
+
+    (1 to 10).foreach { _ =>
+      spark.cloneSession()
+      SparkSession.clearActiveSession()
+    }
+
+    var num = listenersNum()
+    // Before GC, the number of ExecutionListenerBus is (1 + 10)
+    assert(num === 11)
+    eventually(timeout(10.seconds), interval(1.seconds)) {
+      System.gc()
+      num = listenersNum()
+      // After GC, the number of ExecutionListenerBus should be less than 11
+      // Since GC can't 100% guarantee all out-of-referenced objects be cleaned at one time,
+      // here, we check at least one listener is cleaned up to prove the mechanism works.
+      assert(num < 11)

Review comment:
       shall we simply check `assert(num < 10)`? We created 10 sessions and if `num < 10`, it proves the listeners from the session are GCed.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801173090


   @Ngone51 I have noticed you are already a member of the Apache Spark project. Congratulations!
   Would you try merging this one by yourself?


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801641731


   Sure.


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594884615



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,37 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {
+    val spark = SparkSession.builder()
+      .master("local")
+      .getOrCreate()
+
+    def listenersNum(): Int = {
+      spark.sparkContext
+        .listenerBus
+        .listeners
+        .asScala
+        .count(_.isInstanceOf[ExecutionListenerBus])
+    }
+
+    (1 to 10).foreach { _ =>
+      spark.cloneSession()
+      SparkSession.clearActiveSession()
+    }
+
+    var num = listenersNum()
+    // Before GC, the number of ExecutionListenerBus is (1 + 10)
+    assert(num === 11)

Review comment:
       This is unreliable, the GC may happen at any time, even before this assert.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799475269


   **[Test build #136068 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136068/testReport)** for PR 31839 at commit [`b22782a`](https://github.com/apache/spark/commit/b22782a28a71e5479997e55801fddb1ac2f5c5e7).


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r595432805



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala
##########
@@ -76,7 +76,11 @@ trait QueryExecutionListener {
 class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
   extends Logging {
 
-  private val listenerBus = new ExecutionListenerBus(session)
+  private val listenerBus = new ExecutionListenerBus(session.sessionUUID)
+  session.sparkContext.listenerBus.addToSharedQueue(listenerBus)
+  session.sparkContext.cleaner.foreach { cleaner =>

Review comment:
       I'm not against having that assumption. But, this doesn't fix memory leaks at all if `spark.cleaner.referenceTracking=false` technically, does it? We should be clear about the limitation of the PR.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594413798



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -19,18 +19,22 @@ package org.apache.spark.sql
 
 import org.apache.hadoop.fs.Path
 import org.scalatest.BeforeAndAfterEach
+import org.scalatest.concurrent.Eventually
+import org.scalatest.time.SpanSugar._
 
-import org.apache.spark.{SparkConf, SparkContext, SparkException, SparkFunSuite}
+import org.apache.spark.{CleanerListener, SparkConf, SparkContext, SparkException, SparkFunSuite}
 import org.apache.spark.internal.config.EXECUTOR_ALLOW_SPARK_CONTEXT
 import org.apache.spark.internal.config.UI.UI_ENABLED
+import org.apache.spark.scheduler.SparkListener
 import org.apache.spark.sql.internal.SQLConf
 import org.apache.spark.sql.internal.StaticSQLConf._
+import org.apache.spark.sql.util.ExecutionListenerBus
 import org.apache.spark.util.ThreadUtils
 
 /**
  * Test cases for the builder pattern of [[SparkSession]].
  */
-class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
+class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach with Eventually {

Review comment:
       unnecessary changes




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799448866


   cc @cloud-fan 


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-800820647


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136141/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801158438


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40749/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r595725614



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala
##########
@@ -76,7 +76,11 @@ trait QueryExecutionListener {
 class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
   extends Logging {
 
-  private val listenerBus = new ExecutionListenerBus(session)
+  private val listenerBus = new ExecutionListenerBus(session.sessionUUID)
+  session.sparkContext.listenerBus.addToSharedQueue(listenerBus)
+  session.sparkContext.cleaner.foreach { cleaner =>

Review comment:
       Updated.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594391396



##########
File path: core/src/main/scala/org/apache/spark/ContextCleaner.scala
##########
@@ -293,4 +314,5 @@ private[spark] trait CleanerListener {
   def broadcastCleaned(broadcastId: Long): Unit
   def accumCleaned(accId: Long): Unit
   def checkpointCleaned(rddId: Long): Unit
+  def listenerCleaned(listener: SparkListener): Unit

Review comment:
       looking at other methods in this trait, they all take IDs. Should this method take session id?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799944708


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40673/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594876024



##########
File path: core/src/main/scala/org/apache/spark/ContextCleaner.scala
##########
@@ -276,6 +287,16 @@ private[spark] class ContextCleaner(
     }
   }
 
+  def doCleanSparkListener(listener: SparkListener): Unit = {
+    try {
+      logDebug(s"Cleaning Spark listener $listener")

Review comment:
       It logs the qualified class name and JVM object id of that listener, e.g.,
   
   > Cleaning Spark listener org.apache.spark.sql.util.ExecutionListenerBus@54600fe
   
   I think it's enough for users to know which listener is removed.
   
   Others log their own ids because users can track them by analyzing the logs since Spark logs those ids in other places too. But Spark doesn't do that for listeners (and the listener itself doesn't have such an identifier or something else) so it should be enough for now. 




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594839204



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala
##########
@@ -76,7 +76,11 @@ trait QueryExecutionListener {
 class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
   extends Logging {
 
-  private val listenerBus = new ExecutionListenerBus(session)
+  private val listenerBus = new ExecutionListenerBus(session.sessionUUID)
+  session.sparkContext.listenerBus.addToSharedQueue(listenerBus)
+  session.sparkContext.cleaner.foreach { cleaner =>

Review comment:
       To be honest, no. It fixes the memory leak so we generally always want it takes effect. And the `ContextCleaner` is an experienced framework that we can leverage to fix this issue elegantly without aggressive changes.
   
   The config is introduced since Spark 1.0.0 and enabled by default. So I personally think it's acceptable to assume users run applications with cleaner enabled in most cases.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799928463


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136089/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594570603



##########
File path: core/src/main/scala/org/apache/spark/ContextCleaner.scala
##########
@@ -276,6 +287,15 @@ private[spark] class ContextCleaner(
     }
   }
 
+  def doCleanSparkListener(listener: SparkListener): Unit = {
+    try {
+      logDebug(s"Cleaning Spark listener $listener")
+      sc.listenerBus.removeListener(listener)

Review comment:
       Maybe, shall we add a post-log?
   ```scala
   logDebug(s"Cleaned Spark listener $listener")
   ```




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801158438


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40749/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon closed pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #31839:
URL: https://github.com/apache/spark/pull/31839


   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-801582271


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136187/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 closed pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 closed pull request #31839:
URL: https://github.com/apache/spark/pull/31839


   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on a change in pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on a change in pull request #31839:
URL: https://github.com/apache/spark/pull/31839#discussion_r594896918



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala
##########
@@ -40,6 +45,37 @@ class SparkSessionBuilderSuite extends SparkFunSuite with BeforeAndAfterEach {
     SparkSession.clearDefaultSession()
   }
 
+  test("SPARK-34087: Fix memory leak of ExecutionListenerBus") {

Review comment:
       3s+ 




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Ngone51 commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
Ngone51 commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799914667


   > Nice fix! How about adding a test case for this? (the test in "manual test" seems fine)
   
   Added it as the unit test. @gengliangwang 


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-800820647


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136141/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31839: [SPARK-34087][SQL] Fix memory leak of ExecutionListenerBus

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31839:
URL: https://github.com/apache/spark/pull/31839#issuecomment-799485521


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40651/
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org