Skip to content

Commit 6ad06d4

Browse files
committed
Change yarn-standalone to yarn-cluster and fix up running on YARN docs
1 parent 0283665 commit 6ad06d4

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,10 @@ class SparkContext(
736736
key = uri.getScheme match {
737737
// A JAR file which exists only on the driver node
738738
case null | "file" =>
739-
if (SparkHadoopUtil.get.isYarnMode() && master == "yarn-standalone") {
740-
// In order for this to work in yarn standalone mode the user must specify the
739+
// yarn-standalone is deprecated, but still supported
740+
if (SparkHadoopUtil.get.isYarnMode() &&
741+
(master == "yarn-standalone" || master == "yarn-cluster")) {
742+
// In order for this to work in yarn-cluster mode the user must specify the
741743
// --addjars option to the client to upload the file into the distributed cache
742744
// of the AM to make it show up in the current working directory.
743745
val fileName = new Path(uri.getPath).getName()
@@ -1243,7 +1245,7 @@ object SparkContext {
12431245
}
12441246
scheduler
12451247

1246-
case "yarn-standalone" =>
1248+
case "yarn-standalone" | "yarn-cluster" =>
12471249
val scheduler = try {
12481250
val clazz = Class.forName("org.apache.spark.scheduler.cluster.YarnClusterScheduler")
12491251
val cons = clazz.getConstructor(classOf[SparkContext])

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class SparkContextSchedulerCreationSuite
9595
}
9696
}
9797

98+
test("yarn-cluster") {
99+
testYarn("yarn-cluster", "org.apache.spark.scheduler.cluster.YarnClusterScheduler")
100+
}
101+
98102
test("yarn-standalone") {
99103
testYarn("yarn-standalone", "org.apache.spark.scheduler.cluster.YarnClusterScheduler")
100104
}

docs/running-on-yarn.md

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If you want to test out the YARN deployment mode, you can use the current Spark
2929

3030
# Configuration
3131

32-
Most of the configs are the same for Spark on YARN as other deploys. See the Configuration page for more information on those. These are configs that are specific to SPARK on YARN.
32+
Most of the configs are the same for Spark on YARN as for other deployment modes. See the Configuration page for more information on those. These are configs that are specific to Spark on YARN.
3333

3434
Environment variables:
3535

@@ -41,28 +41,30 @@ System Properties:
4141
* `spark.yarn.submit.file.replication`, the HDFS replication level for the files uploaded into HDFS for the application. These include things like the spark jar, the app jar, and any distributed cache files/archives.
4242
* `spark.yarn.preserve.staging.files`, set to true to preserve the staged files(spark jar, app jar, distributed cache files) at the end of the job rather then delete them.
4343
* `spark.yarn.scheduler.heartbeat.interval-ms`, the interval in ms in which the Spark application master heartbeats into the YARN ResourceManager. Default is 5 seconds.
44-
* `spark.yarn.max.worker.failures`, the maximum number of worker failures before failing the application. Default is the number of workers requested times 2 with minimum of 3.
44+
* `spark.yarn.max.worker.failures`, the maximum number of executor failures before failing the application. Default is the number of executors requested times 2 with minimum of 3.
4545

4646
# Launching Spark on YARN
4747

48-
Ensure that HADOOP_CONF_DIR or YARN_CONF_DIR points to the directory which contains the (client side) configuration files for the hadoop cluster.
49-
This would be used to connect to the cluster, write to the dfs and submit jobs to the resource manager.
48+
Ensure that HADOOP_CONF_DIR or YARN_CONF_DIR points to the directory which contains the (client side) configuration files for the Hadoop cluster.
49+
These configs are used to connect to the cluster, write to the dfs, and connect to the YARN ResourceManager.
5050

51-
There are two scheduler mode that can be used to launch spark application on YARN.
51+
There are two scheduler modes that can be used to launch Spark applications on YARN. In yarn-cluster mode, the Spark driver runs inside an application master process which is managed by YARN on the cluster, and the client can go away after initiating the application. In yarn-client mode, the driver runs in the client process, and the application master is only used for requesting resources from YARN.
5252

53-
## Launch spark application by YARN Client with yarn-standalone mode.
53+
Unlike in Spark standalone and Mesos mode, in which the master's address is specified in the "master" parameter, in YARN mode the ResourceManager's address is picked up from the Hadoop configuration. Thus, the master parameter is simply "yarn-client" or "yarn-cluster".
5454

55-
The command to launch the YARN Client is as follows:
55+
## Launching a Spark application with yarn-cluster mode.
56+
57+
The command to launch the Spark application on the cluster is as follows:
5658

5759
SPARK_JAR=<SPARK_ASSEMBLY_JAR_FILE> ./bin/spark-class org.apache.spark.deploy.yarn.Client \
5860
--jar <YOUR_APP_JAR_FILE> \
5961
--class <APP_MAIN_CLASS> \
6062
--args <APP_MAIN_ARGUMENTS> \
61-
--num-workers <NUMBER_OF_WORKER_MACHINES> \
63+
--num-workers <NUMBER_OF_EXECUTORS> \
6264
--master-class <ApplicationMaster_CLASS>
6365
--master-memory <MEMORY_FOR_MASTER> \
64-
--worker-memory <MEMORY_PER_WORKER> \
65-
--worker-cores <CORES_PER_WORKER> \
66+
--worker-memory <MEMORY_PER_EXECUTOR> \
67+
--worker-cores <CORES_PER_EXECUTOR> \
6668
--name <application_name> \
6769
--queue <queue_name> \
6870
--addJars <any_local_files_used_in_SparkContext.addJar> \
@@ -82,35 +84,30 @@ For example:
8284
./bin/spark-class org.apache.spark.deploy.yarn.Client \
8385
--jar examples/target/scala-{{site.SCALA_BINARY_VERSION}}/spark-examples-assembly-{{site.SPARK_VERSION}}.jar \
8486
--class org.apache.spark.examples.SparkPi \
85-
--args yarn-standalone \
87+
--args yarn-cluster \
8688
--num-workers 3 \
8789
--master-memory 4g \
8890
--worker-memory 2g \
8991
--worker-cores 1
9092

91-
# Examine the output (replace $YARN_APP_ID in the following with the "application identifier" output by the previous command)
92-
# (Note: YARN_APP_LOGS_DIR is usually /tmp/logs or $HADOOP_HOME/logs/userlogs depending on the Hadoop version.)
93-
$ cat $YARN_APP_LOGS_DIR/$YARN_APP_ID/container*_000001/stdout
94-
Pi is roughly 3.13794
95-
96-
The above starts a YARN Client programs which start the default Application Master. Then SparkPi will be run as a child thread of Application Master, YARN Client will periodically polls the Application Master for status updates and displays them in the console. The client will exit once your application has finished running.
93+
The above starts a YARN client program which starts the default Application Master. Then SparkPi will be run as a child thread of Application Master. The client will periodically poll the Application Master for status updates and display them in the console. The client will exit once your application has finished running.
9794

98-
With this mode, your application is actually run on the remote machine where the Application Master is run upon. Thus application that involve local interaction will not work well, e.g. spark-shell.
95+
Because the application is run on a remote machine where the Application Master is running, applications that involve local interaction, such as spark-shell, will not work well.
9996

100-
## Launch spark application with yarn-client mode.
97+
## Launching a Spark application with yarn-client mode.
10198

102-
With yarn-client mode, the application will be launched locally. Just like running application or spark-shell on Local / Mesos / Standalone mode. The launch method is also the similar with them, just make sure that when you need to specify a master url, use "yarn-client" instead. And you also need to export the env value for SPARK_JAR.
99+
With yarn-client mode, the application will be launched locally, just like running an application or spark-shell on Local / Mesos / Standalone client mode. The launch method is also the same, just make sure to specify the master URL as "yarn-client". You also need to export the env value for SPARK_JAR.
103100

104101
Configuration in yarn-client mode:
105102

106-
In order to tune worker core/number/memory etc. You need to export environment variables or add them to the spark configuration file (./conf/spark_env.sh). The following are the list of options.
103+
In order to tune worker cores/number/memory etc., you need to export environment variables or add them to the spark configuration file (./conf/spark_env.sh). The following are the list of options.
107104

108-
* `SPARK_WORKER_INSTANCES`, Number of workers to start (Default: 2)
109-
* `SPARK_WORKER_CORES`, Number of cores for the workers (Default: 1).
110-
* `SPARK_WORKER_MEMORY`, Memory per Worker (e.g. 1000M, 2G) (Default: 1G)
105+
* `SPARK_WORKER_INSTANCES`, Number of executors to start (Default: 2)
106+
* `SPARK_WORKER_CORES`, Number of cores per executor (Default: 1).
107+
* `SPARK_WORKER_MEMORY`, Memory per executor (e.g. 1000M, 2G) (Default: 1G)
111108
* `SPARK_MASTER_MEMORY`, Memory for Master (e.g. 1000M, 2G) (Default: 512 Mb)
112109
* `SPARK_YARN_APP_NAME`, The name of your application (Default: Spark)
113-
* `SPARK_YARN_QUEUE`, The hadoop queue to use for allocation requests (Default: 'default')
110+
* `SPARK_YARN_QUEUE`, The YARN queue to use for allocation requests (Default: 'default')
114111
* `SPARK_YARN_DIST_FILES`, Comma separated list of files to be distributed with the job.
115112
* `SPARK_YARN_DIST_ARCHIVES`, Comma separated list of archives to be distributed with the job.
116113

@@ -125,13 +122,23 @@ or
125122
MASTER=yarn-client ./bin/spark-shell
126123

127124

125+
## Viewing logs
126+
127+
In YARN terminology, executors and application masters run inside "containers". YARN has two modes for handling container logs after an application has completed. If log aggregation is turned on (with the yarn.log-aggregation-enable config), container logs are copied to HDFS and deleted on the local machine. These logs can be viewed from anywhere on the cluster with the "yarn logs" command.
128+
129+
yarn logs -applicationId <app ID>
130+
131+
will print out the contents of all log files from all containers from the given application.
132+
133+
When log aggregation isn't turned on, logs are retained locally on each machine under YARN_APP_LOGS_DIR, which is usually configured to /tmp/logs or $HADOOP_HOME/logs/userlogs depending on the Hadoop version and installation. Viewing logs for a container requires going to the host that contains them and looking in this directory. Subdirectories organize log files by application ID and container ID.
134+
128135
# Building Spark for Hadoop/YARN 2.2.x
129136

130-
See [Building Spark with Maven](building-with-maven.html) for instructions on how to build Spark using the Maven process.
137+
See [Building Spark with Maven](building-with-maven.html) for instructions on how to build Spark using Maven.
131138

132139
# Important Notes
133140

134141
- Before Hadoop 2.2, YARN does not support cores in container resource requests. Thus, when running against an earlier version, the numbers of cores given via command line arguments cannot be passed to YARN. Whether core requests are honored in scheduling decisions depends on which scheduler is in use and how it is configured.
135-
- The local directories used for spark will be the local directories configured for YARN (Hadoop Yarn config yarn.nodemanager.local-dirs). If the user specifies spark.local.dir, it will be ignored.
136-
- The --files and --archives options support specifying file names with the # similar to Hadoop. For example you can specify: --files localtest.txt#appSees.txt and this will upload the file you have locally named localtest.txt into HDFS but this will be linked to by the name appSees.txt and your application should use the name as appSees.txt to reference it when running on YARN.
142+
- The local directories used by Spark executors will be the local directories configured for YARN (Hadoop YARN config yarn.nodemanager.local-dirs). If the user specifies spark.local.dir, it will be ignored.
143+
- The --files and --archives options support specifying file names with the # similar to Hadoop. For example you can specify: --files localtest.txt#appSees.txt and this will upload the file you have locally named localtest.txt into HDFS but this will be linked to by the name appSees.txt, and your application should use the name as appSees.txt to reference it when running on YARN.
137144
- The --addJars option allows the SparkContext.addJar function to work if you are using it with local files. It does not need to be used if you are using it with HDFS, HTTP, HTTPS, or FTP files.

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/ClientArguments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class ClientArguments(val args: Array[String], val sparkConf: SparkConf) {
129129
System.err.println(
130130
"Usage: org.apache.spark.deploy.yarn.Client [options] \n" +
131131
"Options:\n" +
132-
" --jar JAR_PATH Path to your application's JAR file (required in yarn-standalone mode)\n" +
132+
" --jar JAR_PATH Path to your application's JAR file (required in yarn-cluster mode)\n" +
133133
" --class CLASS_NAME Name of your application's main class (required)\n" +
134134
" --args ARGS Arguments to be passed to your application's main class.\n" +
135135
" Mutliple invocations are possible, each will be passed in order.\n" +

0 commit comments

Comments
 (0)