You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SPARK-3629] [YARN] [DOCS]: Improvement of the "Running Spark on YARN" document
As per the description in the JIRA, I moved the contents of the page and added a few additional content.
Author: Neelesh Srinivas Salian <[email protected]>
Closes#6924 from nssalian/SPARK-3629 and squashes the following commits:
944b7a0 [Neelesh Srinivas Salian] Changed the lines about deploy-mode and added backticks to all parameters
40dbc0b [Neelesh Srinivas Salian] Changed dfs to HDFS, deploy-mode in backticks and updated the master yarn line
9cbc072 [Neelesh Srinivas Salian] Updated a few lines in the Launching Spark on YARN Section
8e8db7f [Neelesh Srinivas Salian] Removed the changes in this commit to help clearly distinguish movement from update
151c298 [Neelesh Srinivas Salian] SPARK-3629: Improvement of the Spark on YARN document
was added to Spark in version 0.6.0, and improved in subsequent releases.
9
9
10
+
# Launching Spark on YARN
11
+
12
+
Ensure that `HADOOP_CONF_DIR` or `YARN_CONF_DIR` points to the directory which contains the (client side) configuration files for the Hadoop cluster.
13
+
These configs are used to write to HDFS and connect to the YARN ResourceManager. The
14
+
configuration contained in this directory will be distributed to the YARN cluster so that all
15
+
containers used by the application use the same configuration. If the configuration references
16
+
Java system properties or environment variables not managed by YARN, they should also be set in the
17
+
Spark application's configuration (driver, executors, and the AM when running in client mode).
18
+
19
+
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.
20
+
21
+
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 `yarn-client` or `yarn-cluster`.
22
+
To launch a Spark application in `yarn-cluster` mode:
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 "Debugging your Application" section below for how to see driver and executor logs.
39
+
40
+
To launch a Spark application in `yarn-client` mode, do the same, but replace `yarn-cluster` with `yarn-client`. To run spark-shell:
41
+
42
+
$ ./bin/spark-shell --master yarn-client
43
+
44
+
## Adding Other JARs
45
+
46
+
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.
47
+
48
+
$ ./bin/spark-submit --class my.main.Class \
49
+
--master yarn-cluster \
50
+
--jars my-other-jar.jar,my-other-other-jar.jar
51
+
my-main-jar.jar
52
+
app_arg1 app_arg2
53
+
54
+
10
55
# Preparations
11
56
12
57
Running Spark-on-YARN requires a binary distribution of Spark which is built with YARN support.
@@ -17,6 +62,38 @@ To build Spark yourself, refer to [Building Spark](building-spark.html).
17
62
18
63
Most of the configs are the same for Spark on YARN as for other deployment modes. See the [configuration page](configuration.html) for more information on those. These are configs that are specific to Spark on YARN.
19
64
65
+
# Debugging your Application
66
+
67
+
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.
68
+
69
+
yarn logs -applicationId <app ID>
70
+
71
+
will print out the contents of all log files from all containers from the given application. You can also view the container log files directly in HDFS using the HDFS shell or API. The directory where they are located can be found by looking at your YARN configs (`yarn.nodemanager.remote-app-log-dir` and `yarn.nodemanager.remote-app-log-dir-suffix`).
72
+
73
+
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.
74
+
75
+
To review per-container launch environment, increase `yarn.nodemanager.delete.debug-delay-sec` to a
76
+
large value (e.g. 36000), and then access the application cache through `yarn.nodemanager.local-dirs`
77
+
on the nodes on which containers are launched. This directory contains the launch script, JARs, and
78
+
all environment variables used for launching each container. This process is useful for debugging
79
+
classpath problems in particular. (Note that enabling this requires admin privileges on cluster
80
+
settings and a restart of all node managers. Thus, this is not applicable to hosted clusters).
81
+
82
+
To use a custom log4j configuration for the application master or executors, there are two options:
83
+
84
+
- upload a custom `log4j.properties` using `spark-submit`, by adding it to the `--files` list of files
85
+
to be uploaded with the application.
86
+
- add `-Dlog4j.configuration=<location of configuration file>` to `spark.driver.extraJavaOptions`
87
+
(for the driver) or `spark.executor.extraJavaOptions` (for executors). Note that if using a file,
88
+
the `file:` protocol should be explicitly provided, and the file needs to exist locally on all
89
+
the nodes.
90
+
91
+
Note that for the first option, both executors and the application master will share the same
92
+
log4j configuration, which may cause issues when they run on the same node (e.g. trying to write
93
+
to the same log file).
94
+
95
+
If you need a reference to the proper location to put log files in the YARN so that YARN can properly display and aggregate them, use `spark.yarn.app.container.log.dir` in your log4j.properties. For example, `log4j.appender.file_appender.File=${spark.yarn.app.container.log.dir}/spark.log`. For streaming application, configuring `RollingFileAppender` and setting file location to YARN's log directory will avoid disk overflow caused by large log file, and logs can be accessed using YARN's log utility.
96
+
20
97
#### Spark Properties
21
98
22
99
<tableclass="table">
@@ -50,8 +127,8 @@ Most of the configs are the same for Spark on YARN as for other deployment modes
50
127
<td><code>spark.yarn.am.waitTime</code></td>
51
128
<td>100s</td>
52
129
<td>
53
-
In yarn-cluster mode, time for the application master to wait for the
54
-
SparkContext to be initialized. In yarn-client mode, time for the application master to wait
130
+
In `yarn-cluster` mode, time for the application master to wait for the
131
+
SparkContext to be initialized. In `yarn-client` mode, time for the application master to wait
55
132
for the driver to connect to it.
56
133
</td>
57
134
</tr>
@@ -189,8 +266,8 @@ Most of the configs are the same for Spark on YARN as for other deployment modes
189
266
<td>
190
267
Add the environment variable specified by <code>EnvironmentVariableName</code> to the
191
268
Application Master process launched on YARN. The user can specify multiple of
192
-
these and to set multiple environment variables. In yarn-cluster mode this controls
193
-
the environment of the SPARK driver and in yarn-client mode it only controls
269
+
these and to set multiple environment variables. In `yarn-cluster` mode this controls
270
+
the environment of the SPARK driver and in `yarn-client` mode it only controls
194
271
the environment of the executor launcher.
195
272
</td>
196
273
</tr>
@@ -206,7 +283,7 @@ Most of the configs are the same for Spark on YARN as for other deployment modes
206
283
<td>(none)</td>
207
284
<td>
208
285
A string of extra JVM options to pass to the YARN Application Master in client mode.
209
-
In cluster mode, use spark.driver.extraJavaOptions instead.
286
+
In cluster mode, use `spark.driver.extraJavaOptions` instead.
210
287
</td>
211
288
</tr>
212
289
<tr>
@@ -286,83 +363,6 @@ Most of the configs are the same for Spark on YARN as for other deployment modes
286
363
</tr>
287
364
</table>
288
365
289
-
# Launching Spark on YARN
290
-
291
-
Ensure that `HADOOP_CONF_DIR` or `YARN_CONF_DIR` points to the directory which contains the (client side) configuration files for the Hadoop cluster.
292
-
These configs are used to write to the dfs and connect to the YARN ResourceManager. The
293
-
configuration contained in this directory will be distributed to the YARN cluster so that all
294
-
containers used by the application use the same configuration. If the configuration references
295
-
Java system properties or environment variables not managed by YARN, they should also be set in the
296
-
Spark application's configuration (driver, executors, and the AM when running in client mode).
297
-
298
-
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.
299
-
300
-
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".
301
-
302
-
To launch a Spark application in yarn-cluster mode:
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 "Debugging your Application" section below for how to see driver and executor logs.
319
-
320
-
To launch a Spark application in yarn-client mode, do the same, but replace "yarn-cluster" with "yarn-client". To run spark-shell:
321
-
322
-
$ ./bin/spark-shell --master yarn-client
323
-
324
-
## Adding Other JARs
325
-
326
-
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.
327
-
328
-
$ ./bin/spark-submit --class my.main.Class \
329
-
--master yarn-cluster \
330
-
--jars my-other-jar.jar,my-other-other-jar.jar
331
-
my-main-jar.jar
332
-
app_arg1 app_arg2
333
-
334
-
# Debugging your Application
335
-
336
-
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.
337
-
338
-
yarn logs -applicationId <app ID>
339
-
340
-
will print out the contents of all log files from all containers from the given application. You can also view the container log files directly in HDFS using the HDFS shell or API. The directory where they are located can be found by looking at your YARN configs (`yarn.nodemanager.remote-app-log-dir` and `yarn.nodemanager.remote-app-log-dir-suffix`).
341
-
342
-
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.
343
-
344
-
To review per-container launch environment, increase `yarn.nodemanager.delete.debug-delay-sec` to a
345
-
large value (e.g. 36000), and then access the application cache through `yarn.nodemanager.local-dirs`
346
-
on the nodes on which containers are launched. This directory contains the launch script, JARs, and
347
-
all environment variables used for launching each container. This process is useful for debugging
348
-
classpath problems in particular. (Note that enabling this requires admin privileges on cluster
349
-
settings and a restart of all node managers. Thus, this is not applicable to hosted clusters).
350
-
351
-
To use a custom log4j configuration for the application master or executors, there are two options:
352
-
353
-
- upload a custom `log4j.properties` using `spark-submit`, by adding it to the `--files` list of files
354
-
to be uploaded with the application.
355
-
- add `-Dlog4j.configuration=<location of configuration file>` to `spark.driver.extraJavaOptions`
356
-
(for the driver) or `spark.executor.extraJavaOptions` (for executors). Note that if using a file,
357
-
the `file:` protocol should be explicitly provided, and the file needs to exist locally on all
358
-
the nodes.
359
-
360
-
Note that for the first option, both executors and the application master will share the same
361
-
log4j configuration, which may cause issues when they run on the same node (e.g. trying to write
362
-
to the same log file).
363
-
364
-
If you need a reference to the proper location to put log files in the YARN so that YARN can properly display and aggregate them, use `spark.yarn.app.container.log.dir` in your log4j.properties. For example, `log4j.appender.file_appender.File=${spark.yarn.app.container.log.dir}/spark.log`. For streaming application, configuring `RollingFileAppender` and setting file location to YARN's log directory will avoid disk overflow caused by large log file, and logs can be accessed using YARN's log utility.
365
-
366
366
# Important notes
367
367
368
368
- Whether core requests are honored in scheduling decisions depends on which scheduler is in use and how it is configured.
0 commit comments