很多时候为了避免一个任务占用过多的执行资源,阻塞其他任务的执行,需要对单个任务设置执行节点数量的上/下限。
参考官方文档,可以按照以下两种方式进行配置:
1 开启动态分区
spark.dynamicAllocation.enabled=true
如果Spark集群开启动态分区(执行过程中动态使用资源),可以通过以下配置设置执行节点的数量的上/下限
配置 | 值 | 说明 |
---|---|---|
spark.dynamicAllocation.maxExecutors | infinity | 上限,无限制 |
spark.dynamicAllocation.minExecutors | 0 | 下限,至少大于0 |
2 未开启动态分区
spark.dynamicAllocation.enabled=false(默认)
Spark集群默认是关闭动态分区,可以在启动spark任务时指定执行节点的数量。
--num-executors 或者 spark.executor.instances
如在通过livy提交spark任务时,指定num-executors
conf = {
'name': 'mongodb_opt_test2',
'proxyUser': 'xxx',
'numExecutors': 2,
'executorCores': 5,
'executorMemory': '5G',
'driverMemory': '2G',
...
简单的参数调优,可以参考博客 medium.com/expedia-gro…
The consensus in most Spark tuning guides is that 5 cores per executor is the optimum number of cores in terms of parallel processing.
一般来说,每个executor配置5个core最佳。