首页 > 解决方案 > Spark中的客户端模式和集群模式有什么区别?

问题描述

我怀疑什么是客户端模式和集群模式。举个例子:

我有 test.py 有以下内容:

if __name__ == "__main__":

conf = (SparkConf()
     .setAppName(appName)
     .set("spark.executor.memory", ?)
     .set('spark.driver.memory', ?)
     .set('spark.executor.memoryOverhead',?)
     .set("spark.network.timeout", ?)
     .set("spark.files.overwrite", ?)
     .set("spark.executor.heartbeatInterval", ?)
     .set("spark.driver.maxResultSize", ?)
     .set("spark.executor.instances", ?)
     .set("spark.executor.cores", ?)
     .set("spark.driver.cores", ?)
     .set("spark.sql.shuffle.partitions", ?)
     )
spark = SparkSession.builder.config(conf=conf).getOrCreate()

start_time = time.time()
sc = spark.sparkContext
sqlContext = SQLContext(sparkContext = sc)

我在 SSH linux 服务器上工作。为了能够运行 test.py,我可以做两个选择:

1- 使用以下命令保留节点:

salloc --time=03:00:00 --cpus-per-task=32 --mem=0 --account=def-myName

这个命令允许我保留一个节点三个小时。该节点具有以下规范:

Cores: 32
Available memory:   125 gb
CPU type:   2 x Intel E5-2683 v4 "Broadwell" @ 2.1Ghz                         
Storage: 2 x 480GB SSD

现在运行 test.py,我只需输入spark-submit test.py. 这种方式叫客户端模式还是集群模式?如果是客户端模式,我该如何设置:

Master Memory:
Master Cores:
Number of Worker Nodes:
Memory per worker node (gb):
Cores per worker node:

2-我可以运行一个job.shwhere 它的定义如下:

    #SBATCH --nodes=1
    #SBATCH --time=
    #SBATCH --mem=128000M
    #SBATCH --cpus-per-task=
    #SBATCH --ntasks-per-node=
    #SBATCH --output=sparkjob-%j.out
    #SBATCH --mail-type=ALL
    #SBATCH --error=
    ## send mail to this address
    #SBATCH --mail-user=

    spark-submit --total-executor-cores xxx --driver-memory xxxx test.py
....

然后我执行代码sbatch job.sh。这种方式叫集群方式吗?

标签: apache-sparkpyspark

解决方案


客户端模式下驱动程序(执行本地任务)设置在您运行的服务器上spark-submit执行器由您的资源管理器(yarn 或 mesos)在具有您请求的资源的任何节点上动态分配。

集群模式下驱动程序也由资源管理器动态分配,因此可以位于集群的任何节点上。

您可以在此处阅读更多内容https://stackoverflow.com/a/41142747/8467558

部署模式的 spark-submit 内联命令是--deploy-mode

Usage: spark-submit [options] <app jar | python file | R file> [app arguments]
Usage: spark-submit --kill [submission ID] --master [spark://...]
Usage: spark-submit --status [submission ID] --master [spark://...]
Usage: spark-submit run-example [options] example-class [example args]

Options:
  --master MASTER_URL         spark://host:port, mesos://host:port, yarn,
                              k8s://https://host:port, or local (Default: local[*]).
  --deploy-mode DEPLOY_MODE   Whether to launch the driver program locally ("client") or
                              on one of the worker machines inside the cluster ("cluster")
                              (Default: client).

如果未设置,它将默认为您的spark-defaults.conf配置值spark.submit.deployMode。如果没有默认配置或未设置此值,它将是client.


推荐阅读