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以下版本有時候會出現即使有資源也申請不到的情況。
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以下版本有時候會出現即使有資源也申請不到的情況。