Skip to content

[SPARK-53084][CORE] Supplement default GC options in SparkContext initialization #51796

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class SparkContext(config: SparkConf) extends Logging {

SparkContext.supplementJavaModuleOptions(_conf)
SparkContext.supplementJavaIPv6Options(_conf)
SparkContext.supplementJavaGCOptions(_conf)

_driverLogger = DriverLogger(_conf)

Expand Down Expand Up @@ -3435,6 +3436,22 @@ object SparkContext extends Logging {
supplement(DRIVER_JAVA_OPTIONS)
supplement(EXECUTOR_JAVA_OPTIONS)
}

private def supplementJavaGCOptions(conf: SparkConf): Unit = {
def supplement(key: OptionalConfigEntry[String]): Unit = {
conf.get(key).foreach { opts =>
val hasGCAlgorithm = opts.split("\\s+").exists { option =>
option.startsWith("-XX:+Use") && option.endsWith("GC")
}
if (!hasGCAlgorithm) {
conf.set(key.key, s"-XX:+UseParallelGC $opts")
}
}
}

supplement(DRIVER_JAVA_OPTIONS)
supplement(EXECUTOR_JAVA_OPTIONS)
}
}

/**
Expand Down
22 changes: 22 additions & 0 deletions core/src/test/scala/org/apache/spark/SparkContextSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.apache.spark.executor.ExecutorExitCode
import org.apache.spark.internal.config._
import org.apache.spark.internal.config.Tests._
import org.apache.spark.internal.config.UI._
import org.apache.spark.launcher.SparkLauncher
import org.apache.spark.resource.ResourceAllocation
import org.apache.spark.resource.ResourceUtils._
import org.apache.spark.resource.TestResourceIDs._
Expand Down Expand Up @@ -1469,6 +1470,27 @@ class SparkContextSuite extends SparkFunSuite with LocalSparkContext with Eventu
sc.stop()
}

test("SPARK-53084: Supplement UseParallelGC when GC algorithm is not specified") {
val conf = new SparkConf().setAppName("test").setMaster("local")
sc = new SparkContext(conf)
val driverJavaOptions = sc.conf.get(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS)
assert(driverJavaOptions.contains("-XX:+UseParallelGC"))
val executorJavaOptions = sc.getConf.get(EXECUTOR_JAVA_OPTIONS).get
assert(executorJavaOptions.contains("-XX:+UseParallelGC"))
}

test("SPARK-53084: Do not supplement UseParallelGC when GC algorithm is specified") {
val conf = new SparkConf().setAppName("test").setMaster("local")
.set(SparkLauncher.DRIVER_DEFAULT_JAVA_OPTIONS, "-XX:+UseG1GC")
.set(SparkLauncher.EXECUTOR_DEFAULT_JAVA_OPTIONS, "-XX:+UseC4GC")
sc = new SparkContext(conf)
val driverJavaOptions = sc.conf.get(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS)
assert(driverJavaOptions.contains("-XX:+UseG1GC"))
assert(!driverJavaOptions.contains("-XX:+UseParallelGC"))
val executorJavaOptions = sc.getConf.get(EXECUTOR_JAVA_OPTIONS).get
assert(executorJavaOptions.contains("-XX:+UseC4GC"))
assert(!driverJavaOptions.contains("-XX:+UseParallelGC"))
}
}

object SparkContextSuite {
Expand Down