Skip to content

Commit 1c5e1a1

Browse files
wangyumGitHub Enterprise
authored andcommitted
[HADP-58922] Supplement default GC options in SparkContext initialization (apache#821)
1 parent 1e103ba commit 1c5e1a1

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class SparkContext(config: SparkConf) extends Logging {
442442

443443
SparkContext.supplementJavaModuleOptions(_conf)
444444
SparkContext.supplementJavaIPv6Options(_conf)
445-
SparkContext.removeMuiltipleGCFlags(_conf)
445+
SparkContext.supplementJavaGCOptions(_conf)
446446

447447
_driverLogger = DriverLogger(_conf)
448448

@@ -3534,19 +3534,19 @@ object SparkContext extends Logging {
35343534
supplement(EXECUTOR_JAVA_OPTIONS)
35353535
}
35363536

3537-
private def removeMuiltipleGCFlags(conf: SparkConf): Unit = {
3537+
private def supplementJavaGCOptions(conf: SparkConf): Unit = {
35383538
val gcFlags = Set("-XX:+UseG1GC", "-XX:+UseConcMarkSweepGC", "-XX:+UseSerialGC", "-XX:+UseZGC",
35393539
"-XX:+UseShenandoahGC", "-XX:+UseEpsilonGC")
3540-
def remove(key: OptionalConfigEntry[String]): Unit = {
3540+
def supplement(key: OptionalConfigEntry[String]): Unit = {
35413541
conf.get(key).foreach { opts =>
3542-
val splitOpts = opts.split("\\s+")
3543-
if (splitOpts.exists(gcFlags)) {
3544-
conf.set(key.key, splitOpts.filterNot(_ == "-XX:+UseParallelGC").mkString(" "))
3542+
if (!opts.split("\\s+").exists(gcFlags.contains)) {
3543+
conf.set(key.key, s"-XX:+UseParallelGC $opts")
35453544
}
35463545
}
35473546
}
3548-
remove(DRIVER_JAVA_OPTIONS)
3549-
remove(EXECUTOR_JAVA_OPTIONS)
3547+
3548+
supplement(DRIVER_JAVA_OPTIONS)
3549+
supplement(EXECUTOR_JAVA_OPTIONS)
35503550
}
35513551
}
35523552

core/src/test/scala/org/apache/spark/SparkContextSuite.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,19 +1462,26 @@ class SparkContextSuite extends SparkFunSuite with LocalSparkContext with Eventu
14621462
assert(sc.listJars().head.contains(tmpJar.getName))
14631463
}
14641464

1465-
test("Remove UseParallelGC when another GC is specified") {
1465+
test("SPARK-53084: Supplement UseParallelGC when GC algorithm is not specified") {
14661466
val conf = new SparkConf().setAppName("test").setMaster("local")
1467-
.set(SparkLauncher.DRIVER_DEFAULT_JAVA_OPTIONS, " -XX:+UseG1GC")
1468-
.set(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS, "-XX:+UseParallelGC")
1469-
.set(SparkLauncher.EXECUTOR_DEFAULT_JAVA_OPTIONS, " -XX:+UseZGC")
1470-
.set(SparkLauncher.EXECUTOR_EXTRA_JAVA_OPTIONS, "-XX:+UseParallelGC")
1467+
sc = new SparkContext(conf)
1468+
val driverJavaOptions = sc.conf.get(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS)
1469+
assert(driverJavaOptions.contains("-XX:+UseParallelGC"))
1470+
val executorJavaOptions = sc.getConf.get(EXECUTOR_JAVA_OPTIONS).get
1471+
assert(executorJavaOptions.contains("-XX:+UseParallelGC"))
1472+
}
1473+
1474+
test("SPARK-53084: Do not supplement UseParallelGC when GC algorithm is specified") {
1475+
val conf = new SparkConf().setAppName("test").setMaster("local")
1476+
.set(SparkLauncher.DRIVER_DEFAULT_JAVA_OPTIONS,
1477+
"-XX:+UseG1GC -XX:PerMethodRecompilationCutoff=10000")
1478+
.set(SparkLauncher.EXECUTOR_DEFAULT_JAVA_OPTIONS, "-XX:+UseC4GC")
14711479
sc = new SparkContext(conf)
14721480
val driverJavaOptions = sc.conf.get(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS)
14731481
assert(driverJavaOptions.contains("-XX:+UseG1GC"))
14741482
assert(!driverJavaOptions.contains("-XX:+UseParallelGC"))
14751483
val executorJavaOptions = sc.getConf.get(EXECUTOR_JAVA_OPTIONS).get
1476-
assert(executorJavaOptions.contains("-XX:+UseZGC"))
1477-
assert(!executorJavaOptions.contains("-XX:+UseParallelGC"))
1484+
assert(executorJavaOptions.contains("-XX:+UseParallelGC"))
14781485
}
14791486
}
14801487

0 commit comments

Comments
 (0)