Skip to content
Snippets Groups Projects
Commit 744f03e7 authored by Marcelo Vanzin's avatar Marcelo Vanzin
Browse files

[SPARK-10916] [YARN] Set perm gen size when launching containers on YARN.

This makes YARN containers behave like all other processes launched by
Spark, which launch with a default perm gen size of 256m unless
overridden by the user (or not needed by the vm).

Author: Marcelo Vanzin <vanzin@cloudera.com>

Closes #8970 from vanzin/SPARK-10916.
parent 27ecfe61
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,7 @@ private[spark] class WorkerCommandBuilder(sparkHome: String, memoryMb: Int, comm
cmd.add(s"-Xms${memoryMb}M")
cmd.add(s"-Xmx${memoryMb}M")
command.javaOpts.foreach(cmd.add)
addPermGenSizeOpt(cmd)
CommandBuilderUtils.addPermGenSizeOpt(cmd)
addOptionString(cmd, getenv("SPARK_JAVA_OPTS"))
cmd
}
......
......@@ -116,29 +116,6 @@ abstract class AbstractCommandBuilder {
return cmd;
}
/**
* Adds the default perm gen size option for Spark if the VM requires it and the user hasn't
* set it.
*/
void addPermGenSizeOpt(List<String> cmd) {
// Don't set MaxPermSize for IBM Java, or Oracle Java 8 and later.
if (getJavaVendor() == JavaVendor.IBM) {
return;
}
String[] version = System.getProperty("java.version").split("\\.");
if (Integer.parseInt(version[0]) > 1 || Integer.parseInt(version[1]) > 7) {
return;
}
for (String arg : cmd) {
if (arg.startsWith("-XX:MaxPermSize=")) {
return;
}
}
cmd.add("-XX:MaxPermSize=256m");
}
void addOptionString(List<String> cmd, String options) {
if (!isEmpty(options)) {
for (String opt : parseOptionString(options)) {
......
......@@ -313,4 +313,27 @@ class CommandBuilderUtils {
return quoted.append('"').toString();
}
/**
* Adds the default perm gen size option for Spark if the VM requires it and the user hasn't
* set it.
*/
static void addPermGenSizeOpt(List<String> cmd) {
// Don't set MaxPermSize for IBM Java, or Oracle Java 8 and later.
if (getJavaVendor() == JavaVendor.IBM) {
return;
}
String[] version = System.getProperty("java.version").split("\\.");
if (Integer.parseInt(version[0]) > 1 || Integer.parseInt(version[1]) > 7) {
return;
}
for (String arg : cmd) {
if (arg.startsWith("-XX:MaxPermSize=")) {
return;
}
}
cmd.add("-XX:MaxPermSize=256m");
}
}
......@@ -54,8 +54,9 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException
import org.apache.hadoop.yarn.util.Records
import org.apache.spark.deploy.SparkHadoopUtil
import org.apache.spark.{Logging, SecurityManager, SparkConf, SparkContext, SparkException}
import org.apache.spark.deploy.SparkHadoopUtil
import org.apache.spark.launcher.YarnCommandBuilderUtils
import org.apache.spark.util.Utils
private[spark] class Client(
......@@ -730,6 +731,7 @@ private[spark] class Client(
// For log4j configuration to reference
javaOpts += ("-Dspark.yarn.app.container.log.dir=" + ApplicationConstants.LOG_DIR_EXPANSION_VAR)
YarnCommandBuilderUtils.addPermGenSizeOpt(javaOpts)
val userClass =
if (isClusterMode) {
......
......@@ -38,6 +38,7 @@ import org.apache.hadoop.yarn.ipc.YarnRPC
import org.apache.hadoop.yarn.util.{ConverterUtils, Records}
import org.apache.spark.{Logging, SecurityManager, SparkConf, SparkException}
import org.apache.spark.launcher.YarnCommandBuilderUtils
import org.apache.spark.network.util.JavaUtils
import org.apache.spark.util.Utils
......@@ -199,6 +200,7 @@ class ExecutorRunnable(
// For log4j configuration to reference
javaOpts += ("-Dspark.yarn.app.container.log.dir=" + ApplicationConstants.LOG_DIR_EXPANSION_VAR)
YarnCommandBuilderUtils.addPermGenSizeOpt(javaOpts)
val userClassPath = Client.getUserClasspath(sparkConf).flatMap { uri =>
val absPath =
......
......@@ -17,11 +17,28 @@
package org.apache.spark.launcher
import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
/**
* Exposes needed methods
* Exposes methods from the launcher library that are used by the YARN backend.
*/
private[spark] object YarnCommandBuilderUtils {
def quoteForBatchScript(arg: String) : String = {
def quoteForBatchScript(arg: String): String = {
CommandBuilderUtils.quoteForBatchScript(arg)
}
/**
* Adds the perm gen configuration to the list of java options if needed and not yet added.
*
* Note that this method adds the option based on the local JVM version; if the node where
* the container is running has a different Java version, there's a risk that the option will
* not be added (e.g. if the AM is running Java 8 but the container's node is set up to use
* Java 7).
*/
def addPermGenSizeOpt(args: ListBuffer[String]): Unit = {
CommandBuilderUtils.addPermGenSizeOpt(args.asJava)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment