How does Spark-submit in cluster deploy mode manage the application Jars

Viewed 3509

In the Book Spark in Action, i am reading this:

“If you’re submitting your application in cluster-deploy mode using the spark-submit script, the JAR file you specify needs to be available on the worker (at the location you specified) that will be executing the application. Because there’s no way to say in advance which worker will execute your driver, you should put your application’s JAR file on all the workers if you intend to use cluster-deploy mode, or you can put your application’s JAR file on HDFS and use the HDFS URL as the JAR filename.”

But in the official documentation I see this:

1 - If your code depends on other projects, you will need to package them alongside your application in order to distribute the code to a Spark cluster. To do this, create an assembly jar (or “uber” jar) containing your code and its dependencies. Both sbt and Maven have assembly plugins. When creating assembly jars, list Spark and Hadoop as provided dependencies; these need not be bundled since they are provided by the cluster manager at runtime. Once you have an assembled jar you can call the bin/spark-submit script as shown here while passing your jar.

2-If your application is launched through Spark submit, then the application jar is automatically distributed to all worker nodes. For any additional jars that your application depends on, you should specify them through the --jars flag using comma as a delimiter (e.g. --jars jar1,jar2). To control the application’s configuration or execution environment, see Spark Configuration.

What am I missing here ? How does it work ? Do i need to deploy my assembly jar all over the cluster (expect for the master node) ?

4 Answers

The accepted answer from maasg (as well Ajit's answer) assumes that you are submitting to a YARN master. If that is the case, then indeed, your application jar will be provided to the cluster (via HDFS?) automatically.

However, if you are submitting to a Standalone master, and your deploy mode is cluster, then Spark does nothing to distribute your application jar.

The lack of this distinction in the official documentation is rather frustrating. The only place I've ever seen this mentioned is in a git commit comment for fixing SPARK-2260:

One thing that may or may not be an issue is that the jars must be available on the driver node. In standalone-cluster mode, this effectively means these jars must be available on all the worker machines, since the driver is launched on one of them. The semantics here are not the same as yarn-cluster mode, where all the relevant jars are uploaded to a distributed cache automatically and shipped to the containers. This is probably not a concern, but still worth a mention.

TLDR: For a Standalone master, listen to "Spark in Action". For YARN, you won't have this problem.

Related