当前位置:网站首页>Spark3.x入门到精通-阶段七(spark动态资源分配)
Spark3.x入门到精通-阶段七(spark动态资源分配)
2022-07-17 05:24:00 【顶尖高手养成计划】
简介
在spark提交作业以后默认是静态资源分配的,如果有些Executor执行完以后,只要job没有结束,它就会一直占用资源,所以我们要根据情况配置动态资源分配
动态资源分配原理
当调度程序检查到有很多的Task是pending状态的时候,那么它就会尝试去申请新的Executor,如果Executor执行完了以后,就会把资源释放掉给其他的Job使用,它是由spark.dynamicAllocation.schedulerBacklogTimeout这个参数设置的,默认1秒就去检查一次,它申请资源的时候是成倍的去申请的,比如第一个1个,第二次2个,第三次4个,当Executor释放的时候,shuffle写出的数据不会在job停止之前删除,但是Executor缓存的 数据会被删除
standalone模式时使用
准备
开启shuffle-service(它的作用就是在Executor释放以后可以保存shuffle write的数据,只要在提交的机器启动就行)
./start-mesos-shuffle-service.sh查看有没有开启服务 ,如果开启了那么会启动7337端口
sudo netstat -tunlp | grep 7337不使用动态分配情况
./spark-shell --master spark://hadoop102:7077启动以后


可以看到在没有执行action之前已经分配了资源
使用动态分配以后
./spark-shell --master spark://hadoop102:7077 \
--conf spark.shuffle.service.enabled=true \
--conf spark.dynamicAllocation.enabled=true \
--conf spark.dynamicAllocation.executorIdleTimeout=60s \
--conf spark.shuffle.service.port=7337

可以看到,在没有使用action操作前,还没有分配资源
这个时候我们在spark-shell里面执行操作(测试一个wordcount程序)
val lineText=sc.textFile("hdfs://hadoop102:8020/data.txt")lineText.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).foreach(println)
在监控页面我们可以清晰的看到,动态的启动了两个Executor

可以看到执行完以后Executor被移除掉了

Yarn模式使用
准备
配置好spark的历史服务器,然后启动(在我的hive第一阶段有教程)
./start-history-server.sh开始
bin/spark-shell \
--master yarn如图,程序一启动资源就已经分配

使用动态分配的情况
首先在下载好的spark安装包下有一个yarn目录,有一个spark-version-yarn-shuffle.jar,拷贝jar包到yarn的lib目录下,这里面就包含了external shuffle的spark实现。

cp spark-3.0.0-yarn-shuffle.jar ${HADOOP_HOME}/share/hadoop/yarn/lib/spark-3.0.0-yarn-shuffle.jar(注意:不是${HADOOP_HOME}下的lib目录)
修改配置文件
接下来需要修改yarn-site.xml配置文件,增加spark shuffle相关的配置:
<property>
<name>yarn.nodemanager.aux-services</name>
<value>spark_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.spark_shuffle.class</name>
<value>org.apache.spark.network.yarn.YarnShuffleService</value>
</property>
<property>
<name>spark.shuffle.service.port</name>
<value>7337</value>
</property>对于刚才的修改分发到hadoop的其他集群
#xsync是分发脚本在我的shell专栏里面有
./xsync /home/bigdata/hadoop/hadoop/share/hadoop/yarn/lib/分发配置文件
./xsync /home/bigdata/hadoop/hadoop/etc/hadoop重启hadoop集群
./hadoop.sh start测试
bin/spark-shell \
--master yarn \
--conf spark.shuffle.service.enabled=true \
--conf spark.dynamicAllocation.enabled=true \
--conf spark.dynamicAllocation.executorIdleTimeout=60s \
--conf spark.shuffle.service.port=7337上面就是加上了,还有配置了yarn,还有复制了一个jar包到lib目录下
--conf spark.shuffle.service.enabled=true \
--conf spark.dynamicAllocation.enabled=true \
--conf spark.dynamicAllocation.executorIdleTimeout=60s \
--conf spark.shuffle.service.port=7337 \可以看到在没有执行action操作之前就没有分配Exector

在spark-shell执行
val lineText=sc.textFile("hdfs://master:8020/data.txt")lineText.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).foreach(println)执行以后看到如图分配了Exector

60s以后如果Exector没有任务执行那么如下如移除了Exector

多Job调度策略
默认是先进先出,我们可以配置为公平调度器FAIR(spark作为服务端要启动多个job的时候可以配置)
spark.scheduler.mode FIFO边栏推荐
- 网络知识-04 网络层-IPv4协议
- Network knowledge-03 data link layer PPPoE
- Pychart installation tutorial
- Cracking Metric/Business Case/Product Sense Problems
- Review of 4121 Computer System for Data Science
- M simulation of UWB MIMO radar target detection based on MATLAB, considering time reversal
- M simulation of cooperative MIMO distributed space-time coding technology based on MATLAB
- M simulation of 16QAM and 2DPSK communication links based on Simulink, and get the bit error rate curve by calling Simulink model through MATLAB
- Network knowledge-03 data link layer PPP
- M design of GPS data longitude and latitude height analysis and Kalman analysis software based on matlab-GUI
猜你喜欢

实操教程:CANoe在CAN总线测试中的应用

Network knowledge-05 transport layer UDP

解决Mysql (1064) 错误: 1064 - You have an error in your SQL syntax;

Pytorch learning diary (II)

JS does not use async/await to solve the problem of data asynchrony / synchronization

网络知识-04 网络层-IPv4协议

CAN FD如何应用Vector诊断工具链?

TypeScript(一)

High concurrency day02 (concurrent package)

网络知识-04 网络层-ICMP协议
随机推荐
Sword finger offer question brushing record - offer 06 Print linked list from end to end
Solution to the conflict between security automatic login and anti CSRF attack
[quantitative notes] the meaning of relevant technical indicators of volatility
Steam game server configuration selection IP
爬虫基础—Session和Cookie
Review of 4705 NLP
Sword finger offer question brushing record - offer 07 Rebuild binary tree
Matlab implementation code of image denoising method based on Hidden Markov tree model in wavelet domain
网络知识-03 数据链路层-PPP
网络知识-04 网络层-IPv4协议
ivew 穿梭框Transfer组件高亮显示操作值
Network knowledge-03 data link layer PPP
一文带你了解SOA接口测试
Gnome installs the extension (version 40.1, openSUSE tumblefeed).
V2X测试系列之认识V2X第二阶段应用场景
Review of 4246 Algorithms for Data Science
Gentoo installation tutorial (systemd+gnome)
My world 1.18.1 forge version open service tutorial, can install mod, with panel
express
Review of 4121 Computer System for Data Science