当前位置:网站首页>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边栏推荐
- How to open the service of legendary mobile games? How much investment is needed? What do you need?
- JS不使用async/await解决数据异步/同步问题
- Filter filter
- How does the advanced anti DDoS server confirm which are malicious ip/ traffic? ip:103.88.32. XXX
- M simulation of 16QAM and 2DPSK communication links based on Simulink, and get the bit error rate curve by calling Simulink model through MATLAB
- Pytorch learning diary (4)
- 网络知识-03 数据链路层-PPP
- Xiaodi network security note information collection CDN bypass technology (7)
- Minecraft integration package [gtnh] gray Technology: new vision server building tutorial
- Fundamentals of crawlers - basic principles of multithreading and multiprocessing
猜你喜欢
随机推荐
How to output a digital diamond with a for loop
What role does 5g era server play in this?
M simulation of 16QAM and 2DPSK communication links based on Simulink, and get the bit error rate curve by calling Simulink model through MATLAB
A2B音频总线在智能座舱中的应用
MySQL decompression installation steps (Windows)
爬虫基础—多线程和多进程的基本原理
MySql
WCDMA soft handoff performance matlab simulation m, comparing the average number of activation sets (MasN), activation set update rate (Asur) and call interruption probability (OP) three performance i
爬虫基础—爬虫的基本原理
Pytorch learning diary (II)
网络知识-02 物理层
Solution to the conflict between security automatic login and anti CSRF attack
I heard that today's blog can get a badge!
JS不使用async/await解决数据异步/同步问题
Arrayslist method
Review of 4705 NLP
Pytorch learning diary (4)
Execute shell script under Linux to call SQL file and transfer it to remote server
Summary of Statistics for Interview
Security自动登录与防CSRF攻击冲突解决办法









