-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-22471][SQL] SQLListener consumes much memory causing OutOfMemoryError #19711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08b7c82
Add reproducer for the issue SPARK-22471
tashoyan 2502a7e
Add fix for the issue SPARK-22471
tashoyan 2a13530
Remove debug print and irrelevant checks. Add a reference to the issue.
tashoyan 98f7b23
Remove debug print and irrelevant checks. Add a reference to the issue.
tashoyan 80755ec
Collect memory-related tests on SQLListener in the same suite
tashoyan 4a0582d
Don't hardcode magic numbers
tashoyan 3ecce56
Synchronize access to _stageIdToStageMetrics
tashoyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
sql/core/src/test/scala/org/apache/spark/sql/execution/ui/SQLListenerMemorySuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * 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.sql.execution.ui | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkContext, SparkException, SparkFunSuite} | ||
| import org.apache.spark.LocalSparkContext.withSpark | ||
| import org.apache.spark.internal.config | ||
| import org.apache.spark.sql.{Column, SparkSession} | ||
| import org.apache.spark.sql.catalyst.util.quietly | ||
| import org.apache.spark.sql.functions._ | ||
|
|
||
| class SQLListenerMemorySuite extends SparkFunSuite { | ||
|
|
||
| test("SPARK-22471 - _stageIdToStageMetrics grows too large on long executions") { | ||
| quietly { | ||
| val conf = new SparkConf() | ||
| .setMaster("local[*]") | ||
| .setAppName("MemoryLeakTest") | ||
| /* Don't retry the tasks to run this test quickly */ | ||
| .set(config.MAX_TASK_FAILURES, 1) | ||
| .set("spark.ui.retainedStages", "50") | ||
| withSpark(new SparkContext(conf)) { sc => | ||
| SparkSession.sqlListener.set(null) | ||
| val spark = new SparkSession(sc) | ||
| import spark.implicits._ | ||
|
|
||
| val sample = List( | ||
| (1, 10), | ||
| (2, 20), | ||
| (3, 30) | ||
| ).toDF("id", "value") | ||
|
|
||
| /* Some complex computation with many stages. */ | ||
| val joins = 1 to 100 | ||
| val summedCol: Column = joins | ||
| .map(j => col(s"value$j")) | ||
| .reduce(_ + _) | ||
| val res = joins | ||
| .map { j => | ||
| sample.select($"id", $"value" * j as s"value$j") | ||
| } | ||
| .reduce(_.join(_, "id")) | ||
| .select($"id", summedCol as "value") | ||
| .groupBy("id") | ||
| .agg(sum($"value") as "value") | ||
| .orderBy("id") | ||
| res.collect() | ||
|
|
||
| sc.listenerBus.waitUntilEmpty(10000) | ||
| assert(spark.sharedState.listener.stageIdToStageMetrics.size <= 50) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("no memory leak") { | ||
| quietly { | ||
| val conf = new SparkConf() | ||
| .setMaster("local") | ||
| .setAppName("test") | ||
| .set(config.MAX_TASK_FAILURES, 1) // Don't retry the tasks to run this test quickly | ||
| .set("spark.sql.ui.retainedExecutions", "50") // Set it to 50 to run this test quickly | ||
| withSpark(new SparkContext(conf)) { sc => | ||
| SparkSession.sqlListener.set(null) | ||
| val spark = new SparkSession(sc) | ||
| import spark.implicits._ | ||
| // Run 100 successful executions and 100 failed executions. | ||
| // Each execution only has one job and one stage. | ||
| for (i <- 0 until 100) { | ||
| val df = Seq( | ||
| (1, 1), | ||
| (2, 2) | ||
| ).toDF() | ||
| df.collect() | ||
| try { | ||
| df.foreach(_ => throw new RuntimeException("Oops")) | ||
| } catch { | ||
| case e: SparkException => // This is expected for a failed job | ||
| } | ||
| } | ||
| sc.listenerBus.waitUntilEmpty(10000) | ||
| assert(spark.sharedState.listener.getCompletedExecutions.size <= 50) | ||
| assert(spark.sharedState.listener.getFailedExecutions.size <= 50) | ||
| // 50 for successful executions and 50 for failed executions | ||
| assert(spark.sharedState.listener.executionIdToData.size <= 100) | ||
| assert(spark.sharedState.listener.jobIdToExecutionId.size <= 100) | ||
| assert(spark.sharedState.listener.stageIdToStageMetrics.size <= 100) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use Java's
LinkedHashMapand overrideremoveEldestEntryto what we want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removeEldestEntryis a protected method.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java's
LinkedHashMapcan be overridden with a custom implementation ofremoveEldestEntry, that will save the codes done below. It is not the user who call thisremoveEldestEntry...