Skip to content

Commit a314342

Browse files
sryzapwendell
authored andcommitted
SPARK-1492. Update Spark YARN docs to use spark-submit
Author: Sandy Ryza <[email protected]> Closes #601 from sryza/sandy-spark-1492 and squashes the following commits: 5df1634 [Sandy Ryza] Address additional comments from Patrick. be46d1f [Sandy Ryza] Address feedback from Marcelo and Patrick 867a3ea [Sandy Ryza] SPARK-1492. Update Spark YARN docs to use spark-submit (cherry picked from commit 2b961d8) Signed-off-by: Patrick Wendell <[email protected]>
1 parent b65def7 commit a314342

File tree

2 files changed

+38
-94
lines changed

2 files changed

+38
-94
lines changed

docs/cluster-overview.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ the `--help` flag. Here are a few examples of common options:
8686
--master local[8] \
8787
my-app.jar
8888

89-
# Run on a Spark cluster
89+
# Run on a Spark standalone cluster
9090
./bin/spark-submit \
9191
--class my.main.ClassName
9292
--master spark://mycluster:7077 \
@@ -118,21 +118,22 @@ If you are ever unclear where configuration options are coming from. fine-graine
118118
information can be printed by adding the `--verbose` option to `./spark-submit`.
119119

120120
### Advanced Dependency Management
121-
When using `./bin/spark-submit` jars will be automatically transferred to the cluster. For many
122-
users this is sufficient. However, advanced users can add jars by calling `addFile` or `addJar`
123-
on an existing SparkContext. This can be used to distribute JAR files (Java/Scala) or .egg and
124-
.zip libraries (Python) to executors. Spark uses the following URL scheme to allow different
121+
When using `./bin/spark-submit` the app jar along with any jars included with the `--jars` option
122+
will be automatically transferred to the cluster. `--jars` can also be used to distribute .egg and .zip
123+
libraries for Python to executors. Spark uses the following URL scheme to allow different
125124
strategies for disseminating jars:
126125

127126
- **file:** - Absolute paths and `file:/` URIs are served by the driver's HTTP file server, and
128-
every executor pulls the file from the driver HTTP server
127+
every executor pulls the file from the driver HTTP server.
129128
- **hdfs:**, **http:**, **https:**, **ftp:** - these pull down files and JARs from the URI as expected
130129
- **local:** - a URI starting with local:/ is expected to exist as a local file on each worker node. This
131130
means that no network IO will be incurred, and works well for large files/JARs that are pushed to each worker,
132131
or shared via NFS, GlusterFS, etc.
133132

134133
Note that JARs and files are copied to the working directory for each SparkContext on the executor nodes.
135-
Over time this can use up a significant amount of space and will need to be cleaned up.
134+
This can use up a significant amount of space over time and will need to be cleaned up. With YARN, cleanup
135+
is handled automatically, and with Spark standalone, automatic cleanup can be configured with the
136+
`spark.worker.cleanup.appDataTtl` property.
136137

137138
# Monitoring
138139

docs/running-on-yarn.md

Lines changed: 30 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,13 @@ title: Launching Spark on YARN
55

66
Support for running on [YARN (Hadoop
77
NextGen)](http://hadoop.apache.org/docs/r2.0.2-alpha/hadoop-yarn/hadoop-yarn-site/YARN.html)
8-
was added to Spark in version 0.6.0, and improved in 0.7.0 and 0.8.0.
9-
10-
# Building a YARN-Enabled Assembly JAR
11-
12-
We need a consolidated Spark JAR (which bundles all the required dependencies) to run Spark jobs on a YARN cluster.
13-
This can be built by setting the Hadoop version and `SPARK_YARN` environment variable, as follows:
14-
15-
SPARK_HADOOP_VERSION=2.0.5-alpha SPARK_YARN=true sbt/sbt assembly
16-
17-
The assembled JAR will be something like this:
18-
`./assembly/target/scala-{{site.SCALA_BINARY_VERSION}}/spark-assembly_{{site.SPARK_VERSION}}-hadoop2.0.5.jar`.
19-
20-
The build process now also supports new YARN versions (2.2.x). See below.
8+
was added to Spark in version 0.6.0, and improved in subsequent releases.
219

2210
# Preparations
2311

24-
- Building a YARN-enabled assembly (see above).
25-
- The assembled jar can be installed into HDFS or used locally.
26-
- Your application code must be packaged into a separate JAR file.
27-
28-
If you want to test out the YARN deployment mode, you can use the current Spark examples. A `spark-examples_{{site.SCALA_BINARY_VERSION}}-{{site.SPARK_VERSION}}` file can be generated by running `sbt/sbt assembly`. NOTE: since the documentation you're reading is for Spark version {{site.SPARK_VERSION}}, we are assuming here that you have downloaded Spark {{site.SPARK_VERSION}} or checked it out of source control. If you are using a different version of Spark, the version numbers in the jar generated by the sbt package command will obviously be different.
12+
Running Spark-on-YARN requires a binary distribution of Spark which is built with YARN support.
13+
Binary distributions can be downloaded from the Spark project website.
14+
To build Spark yourself, refer to the [building with maven guide](building-with-maven.html).
2915

3016
# Configuration
3117

@@ -44,86 +30,47 @@ System Properties:
4430
* `spark.yarn.max.executor.failures`, the maximum number of executor failures before failing the application. Default is the number of executors requested times 2 with minimum of 3.
4531
* `spark.yarn.historyServer.address`, the address of the Spark history server (i.e. host.com:18080). The address should not contain a scheme (http://). Defaults to not being set since the history server is an optional service. This address is given to the Yarn ResourceManager when the Spark application finishes to link the application from the ResourceManager UI to the Spark history server UI.
4632

33+
By default, Spark on YARN will use a Spark jar installed locally, but the Spark jar can also be in a world-readable location on HDFS. This allows YARN to cache it on nodes so that it doesn't need to be distributed each time an application runs. To point to a jar on HDFS, export SPARK_JAR=hdfs:///some/path.
34+
4735
# Launching Spark on YARN
4836

4937
Ensure that HADOOP_CONF_DIR or YARN_CONF_DIR points to the directory which contains the (client side) configuration files for the Hadoop cluster.
50-
These configs are used to connect to the cluster, write to the dfs, and connect to the YARN ResourceManager.
38+
These configs are used to write to the dfs and connect to the YARN ResourceManager.
5139

5240
There are two deploy 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.
5341

5442
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".
5543

56-
The spark-submit script described in the [cluster mode overview](cluster-overview.html) provides the most straightforward way to submit a compiled Spark application to YARN in either deploy mode. For info on the lower-level invocations it uses, read ahead. For running spark-shell against YARN, skip down to the yarn-client section.
57-
58-
## Launching a Spark application with yarn-cluster mode.
59-
60-
The command to launch the Spark application on the cluster is as follows:
61-
62-
SPARK_JAR=<SPARK_ASSEMBLY_JAR_FILE> ./bin/spark-class org.apache.spark.deploy.yarn.Client \
63-
--jar <YOUR_APP_JAR_FILE> \
64-
--class <APP_MAIN_CLASS> \
65-
--arg <APP_MAIN_ARGUMENT> \
66-
--num-executors <NUMBER_OF_EXECUTOR_PROCESSES> \
67-
--driver-memory <MEMORY_FOR_ApplicationMaster> \
68-
--executor-memory <MEMORY_PER_EXECUTOR> \
69-
--executor-cores <CORES_PER_EXECUTOR> \
70-
--name <application_name> \
71-
--queue <queue_name> \
72-
--addJars <any_local_files_used_in_SparkContext.addJar> \
73-
--files <files_for_distributed_cache> \
74-
--archives <archives_for_distributed_cache>
75-
76-
To pass multiple arguments the "arg" option can be specified multiple times. For example:
77-
78-
# Build the Spark assembly JAR and the Spark examples JAR
79-
$ SPARK_HADOOP_VERSION=2.0.5-alpha SPARK_YARN=true sbt/sbt assembly
80-
81-
# Configure logging
82-
$ cp conf/log4j.properties.template conf/log4j.properties
83-
84-
# Submit Spark's ApplicationMaster to YARN's ResourceManager, and instruct Spark to run the SparkPi example
85-
$ SPARK_JAR=./assembly/target/scala-{{site.SCALA_BINARY_VERSION}}/spark-assembly-{{site.SPARK_VERSION}}-hadoop2.0.5-alpha.jar \
86-
./bin/spark-class org.apache.spark.deploy.yarn.Client \
87-
--jar examples/target/scala-{{site.SCALA_BINARY_VERSION}}/spark-examples-assembly-{{site.SPARK_VERSION}}.jar \
88-
--class org.apache.spark.examples.SparkPi \
89-
--arg yarn-cluster \
90-
--arg 5 \
91-
--num-executors 3 \
92-
--driver-memory 4g \
93-
--executor-memory 2g \
94-
--executor-cores 1
95-
96-
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. Refer to the "Viewing Logs" section below for how to see driver and executor logs.
97-
98-
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.
99-
100-
## Launching a Spark application with yarn-client mode.
101-
102-
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.
44+
To launch a Spark application in yarn-cluster mode:
10345

104-
Configuration in yarn-client mode:
46+
./bin/spark-submit --class path.to.your.Class --master yarn-cluster [options] <app jar> [app options]
47+
48+
For example:
10549

106-
In order to tune executor 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.
50+
$ ./bin/spark-submit --class org.apache.spark.examples.SparkPi \
51+
--master yarn-cluster \
52+
--num-executors 3 \
53+
--driver-memory 4g \
54+
--executor-memory 2g \
55+
--executor-cores 1
56+
examples/target/scala-{{site.SCALA_BINARY_VERSION}}/spark-examples-assembly-{{site.SPARK_VERSION}}.jar \
57+
yarn-cluster 5
10758

108-
* `SPARK_EXECUTOR_INSTANCES`, Number of executors to start (Default: 2)
109-
* `SPARK_EXECUTOR_CORES`, Number of cores per executor (Default: 1).
110-
* `SPARK_EXECUTOR_MEMORY`, Memory per executor (e.g. 1000M, 2G) (Default: 1G)
111-
* `SPARK_DRIVER_MEMORY`, Memory for driver (e.g. 1000M, 2G) (Default: 512 Mb)
112-
* `SPARK_YARN_APP_NAME`, The name of your application (Default: Spark)
113-
* `SPARK_YARN_QUEUE`, The YARN queue to use for allocation requests (Default: 'default')
114-
* `SPARK_YARN_DIST_FILES`, Comma separated list of files to be distributed with the job.
115-
* `SPARK_YARN_DIST_ARCHIVES`, Comma separated list of archives to be distributed with the job.
59+
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. Refer to the "Viewing Logs" section below for how to see driver and executor logs.
11660

117-
For example:
61+
To launch a Spark application in yarn-client mode, do the same, but replace "yarn-cluster" with "yarn-client". To run spark-shell:
11862

119-
SPARK_JAR=./assembly/target/scala-{{site.SCALA_BINARY_VERSION}}/spark-assembly-{{site.SPARK_VERSION}}-hadoop2.0.5-alpha.jar \
120-
./bin/run-example org.apache.spark.examples.SparkPi yarn-client
63+
$ MASTER=yarn-client ./bin/spark-shell
12164

122-
or
65+
## Adding additional jars
12366

124-
SPARK_JAR=./assembly/target/scala-{{site.SCALA_BINARY_VERSION}}/spark-assembly-{{site.SPARK_VERSION}}-hadoop2.0.5-alpha.jar \
125-
MASTER=yarn-client ./bin/spark-shell
67+
In yarn-cluster mode, the driver runs on a different machine than the client, so SparkContext.addJar won't work out of the box with files that are local to the client. To make files on the client available to SparkContext.addJar, include them with the `--jars` option in the launch command.
12668

69+
$ ./bin/spark-submit --class my.main.Class \
70+
--master yarn-cluster \
71+
--jars my-other-jar.jar,my-other-other-jar.jar
72+
my-main-jar.jar
73+
yarn-cluster 5
12774

12875
# Viewing logs
12976

@@ -135,13 +82,9 @@ will print out the contents of all log files from all containers from the given
13582

13683
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.
13784

138-
# Building Spark for Hadoop/YARN 2.2.x
139-
140-
See [Building Spark with Maven](building-with-maven.html) for instructions on how to build Spark using Maven.
141-
14285
# Important notes
14386

14487
- 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.
14588
- 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.
14689
- 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.
147-
- 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.
90+
- The --jars option allows the SparkContext.addJar function to work if you are using it with local files and running in yarn-cluster mode. It does not need to be used if you are using it with HDFS, HTTP, HTTPS, or FTP files.

0 commit comments

Comments
 (0)