如何在Spark集群的work节点上启动多个Executor

2025-04-28 05:09:20
推荐回答(1个)
回答1:

1、设置每个executor使用的cpu数为4

spark.executor.cores 4
2、限制cpu使用数量,这里会启动3个executor(12/4)

spark.cores.max 12
3、设置每个executor的内存大小为8g

spark.executor.memory 12g
以上设置将会启动3个executor,每个executor使用4cpu,12gRAM。
总共占用worker资源12cpu,36gRAM。

Spark1.6的源码部分为:

protected final String EXECUTOR_MEMORY = "--executor-memory";protected final String TOTAL_EXECUTOR_CORES = "--total-executor-cores";protected final String EXECUTOR_CORES = "--executor-cores";
也可以在提交任务的时候添加:

SparkSubmit --class com.dyq.spark.MyClass --master:spark://master:7077 --total-executor-cores 12 --executor-cores 24 --executor-memory 12g
tip

在使用过程中发现如果使用spark1.5以下版本有时候会出现即使有资源也申请不到的情况。