当前位置:网站首页>Spark调优(提交作业资源参数调优)
Spark调优(提交作业资源参数调优)
2022-06-28 17:20:00 【Keven He】
Spark调优(提交job资源参数调优)
Spark提交作业job的时候要指定该job可以使用的CPU、内存等资源参数,生产环境中,任务资源分配不足会导致该job执行中断、失败等问题,所以对Spark的job资源参数分配调优非常重要。
#! /bin/bash
cd `dirname $0`
dir=`pwd`
echo $dir
jars=$(echo ${
dir}/jars/*.jar | tr ' ' ',')
echo ${jars}
spark2-submit --master yarn --deploy-mode cluster
--executor-memory 10G
--num-executors 15
--executor-cores 8
--conf spark.sql.shuffle.partitions=200
--conf spark.dynamicAllocation.enabled=false
--conf spark.network.timeout=600
--conf spark.kryoserializer.buffer.max=512m
--conf spark.kryoserializer.buffer=64m
--conf spark.driver.maxResultSize=0
--conf spark.yarn.am.waitTime=1000s
--queue root.system.ys--jars ${jars}
--class com.App ${dir}/xxxx.jar "xxxxxxxxxxxx"
echo end
- num-executors
参数说明:该参数用于设置每个Spark作业总共要用多少个Executor进程来执行。例如Driver向YARN集群管理器申请资源时,YARN集群管理器会尽可能按照该配置在集群的各个worker节点上启动相应数量的Executor进程。如果不设置的话,Spark默认只启动少量的Executor进程,意味着该Spark作业并行度不足,如果作业计算多、数据很大,会导致运行速度非常慢甚至资源不足,异常中断,无法完成等。
调优建议:num-executors设置太少或太多的Executor进程都不好。设置的太少,无法充分利用集群资源;设置的太多的话,大部分队列可能无法给予充分的资源。生产环境经验是每个Spark作业的运行一般设置50~100个左右的Executor进程比较合适。
- executor-memory
参数说明:该参数用于设置每个Executor进程的内存。Executor内存的大小,很多时候直接决定了Spark作业的性能,跟常见的JVM OOM异常也有直接关系。
调优建议:如果内存资源充足的前提下,一般每个job给每个Executor进程的内存设置4G~8G较为合适。具体的设置还得根据Spark集群可以占用的内存资源总量来定。(num-executors * executor-memory,是本Spark作业申请到的内存资源量,这个值是不能超过Spark集群可以占用的内存资源总量的)
- executor-cores
参数说明:该参数用于设置每个Executor进程的CPU cores数量。这个参数决定了每个Executor进程并行执行task线程的能力。因为每个CPU core同一时间只能执行一个task线程,因此每个Executor进程的CPU cores数量越多,越能够快速地并行执行完分配给自己的所有task线程。
调优建议:如果CPU核数资源充足的前提下,一般每个job给每个Executor的CPU core数量设置为2~4个较为合适。具体的设置根据Spark集群可以占用的CPU core数量资源总量来定。(num-executors * executor-cores,是本Spark作业申请到的CPU core数量,这个值是不能超过Spark集群可以占用的CPU core数量资源总量的)
- driver-memory
参数说明:该参数用于设置Driver进程的内存。
调优建议:Driver的内存通常来说不设置,或者设置1G左右应该就够了。唯一需要注意的一点是,如果需要使用collect算子将RDD的数据全部拉取到Driver上进行处理,那么必须确保Driver的内存足够大,否则会出现OOM内存溢出的问题。
- spark.default.parallelism
参数说明:该参数用于设置每个stage的默认task数量。这个参数极为重要,如果不设置可能会直接影响Spark作业性能。
调优建议:如果不设置这个参数,会导致Spark自己根据底层HDFS的block数量来设置task的数量,默认是一个HDFS block对应一个task。(通常来说,Spark默认设置的数量是偏少的(比如就几十个task),如果task数量偏少的话,就会导致你前面设置好的Executor的参数都前功尽弃。试想一下,无论Executor进程有多少个,内存和CPU资源分配有多充足,但是task只有1个或者10个,那么90%的Executor进程可能根本就没有task执行,也就是白白浪费了宝贵的内存和CPU资源!)因此Spark官网建议的设置原则是,设置该参数为num-executors * executor-cores的2~3倍较为合适,例如,Executor的总CPU core数量为300个,那么设置1000个task是可以的,此时可以充分地利用Spark集群的资源,也就是说,1个cpu core并发跑2~3个task是较为合适的。
- spark.driver.maxResultSize
参数说明:spark.driver.maxResultSize默认大小为1G 每个Spark action(如collect)所有分区的序列化结果的总大小限制,简而言之就是executor给driver返回的结果过大,报这个错说明需要提高这个值或者避免使用类似的方法,比如countByValue,countByKey等。
调优建议:
设置spark.driver.maxResultSize过大可能会导致driver端的OOM错误。设置合适的大小可以保护driver免受内存不足错误的影响。
- spark.kryoserializer.buffer.max
参数说明:Kryo序列化缓冲区max值,调节spark.kryoserializer.buffer.max的value,来使得spark任务可以平滑的进入缓冲区。
- spark.kryoserializer.buffer
参数说明:
设置kryo序列化缓冲区的大小。
调优建议:
如果要被序列化的对象很大,这个时候就最好将配置项spark.kryoserializer.buffer 的值(默认64k)设置的大些,使得其能够hold要序列化的最大的对象。
边栏推荐
- Xiaoxin black apple sound card ID injection
- 2022年化工自动化控制仪表考试模拟100题模拟考试平台操作
- 58技术沙龙第三十一期|Flutter动态化专题沙龙
- Ding! Techo day Tencent technology open day arrived as scheduled!
- 2022 practice questions and mock examination of Shandong Province safety officer C certificate examination
- This simple little function saves 213 hours for our production research team in half a year
- TDengine ×英特尔 边缘洞见软件包 加速传统行业的数字化转型
- Redis持久化(少年一贯快马扬帆,道阻且长不转弯)
- [algorithm] I brushed two big factory interview questions and learned array again with tears in my eyes“
- Can tongdaxin open an account for stock trading? Is it safe?
猜你喜欢

MySQL high availability MHA (accidentally passed my youth)

Time effective simulation platform based on dataworks | acquisition technology

2022A特种设备相关管理(电梯)特种作业证考试题库及在线模拟考试

第四个专栏,Kubernetes云原生实战,它来了~

58技术沙龙第三十一期|Flutter动态化专题沙龙

使用Pega进行一个简单的RPA程序开发

The processor of this virtual machine supports different functions than the processor of the virtual machine that holds the state of the virtual machine

Flutter 小技巧之 MediaQuery 和 build 优化你不知道的秘密

Why insert is configured with'select last_ INSERT_ What if id() 'returns 0?

Redis持久化(少年一贯快马扬帆,道阻且长不转弯)
随机推荐
MySQL高可用之MHA(一不小心和我的青春擦肩而過)
From getting started to mastering the application of | yalmip+cplex in power system (excellent, I will lose if I can't understand it, and I will lose if I don't gain)
区间乘积的因子数之和
Dpdk 20.11 compiling, installing and running program
Is the account opening link given by CICC securities manager safe? Who can I open an account with?
NP tips: random create random matrix sample = np random. random([19, 64 , 64, 3])
Leetcode 6. Z 字形变换(牛逼,解决了)
MySQL中的日志管理 日志備份與恢複
2022 recurrent training question bank and online simulation examination for main principals of hazardous chemicals business units
Google推出Advanced API Security 保护API免受安全威胁
Pure big resentment! Those who were discouraged from taking the postgraduate entrance examination
WPF video hard decoding, rendering and playing (no airspace) (support 4K, 8K and high frame rate video)
节点基础~节点层级
Visubit "ai+3d vision" product series | loading assembly workstation
Log management in MySQL log backup and recovery
VirtualBox中克隆了一个虚拟系统出现IP问题
Problems encountered in local deployment conflict: MySQL database code, isolation level and verification code are not displayed
TDengine ×英特尔 边缘洞见软件包 加速传统行业的数字化转型
The MySQL installed in Alibaba cloud server is version 8. Is it because the MySQL driver version of dataworks does not support it? Now mention
此虚拟机的处理器所支持的功能不同于保存虚拟机状态的虚拟机的处理器所支持的功能