How to know deploy mode of PySpark application?

好久不见. 提交于 2019-11-29 10:36:29

If you are running an interactive shell, e.g. pyspark (CLI or via an IPython notebook), by default you are running in client mode. You can easily verify that you cannot run pyspark or any other interactive shell in cluster mode:

$ pyspark --master yarn --deploy-mode cluster
Python 2.7.11 (default, Mar 22 2016, 01:42:54)
[GCC Intel(R) C++ gcc 4.8 mode] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Error: Cluster deploy mode is not applicable to Spark shells.

$ spark-shell --master yarn --deploy-mode cluster
Error: Cluster deploy mode is not applicable to Spark shells.

Examining the contents of the bin/pyspark file may be instructive, too - here is the final line (which is the actual executable):

$ pwd
/home/ctsats/spark-1.6.1-bin-hadoop2.6
$ cat bin/pyspark
[...]
exec "${SPARK_HOME}"/bin/spark-submit pyspark-shell-main --name "PySparkShell" "$@"

i.e. pyspark is actually a script run by spark-submit and given the name PySparkShell, by which you can find it in the Spark History Server UI; and since it is run like that, it goes by whatever arguments (or defaults) are included with its spark-submit command.

Since sc.deployMode is not available in PySpark, you could check spark.submit.deployMode

scala> sc.getConf.get("spark.submit.deployMode")
res0: String = client

This is not available in PySpark

Use sc.deployMode

scala> sc.deployMode
res0: String = client

scala> sc.version
res1: String = 2.1.0-SNAPSHOT
Prasanna Saraswathi Krishnan

As of Spark 2+ the below works.

for item in spark.sparkContext.getConf().getAll():print(item)

(u'spark.submit.deployMode', u'client') # will be one of the items in the list.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!