当前位置:网站首页>DATA AI Summit 2022提及到的对 aggregate 的优化
DATA AI Summit 2022提及到的对 aggregate 的优化
2022-07-31 00:02:00 【鸿乃江边鸟】
背景
本文基于SPARK 3.3.0
HashAggregate的优化
该优化是FaceBook(Meta) 内部的优化,还有合并到spark社区。
该优化的主要是partialaggregate的部分:对于类似求count,sum,Avg的聚合操作,会存在现在mapper进行部分聚合的操作,之后在reduce端,再进行FinalAggregate操作。这看起来是没有问题的(能够很好的减少网络IO),但是我们知道对于聚合操作,我们会进行数据的spill的操作,如果在mapper阶段合并的数据很少,以至于抵消不了网络IO带来的消耗的话,这无疑会给任务带来损耗。



利用运行时的指标信息,能够达到比较好的加速效果。
ObjectHashAggregate的优化
对于ObjectHashAggreate的原理,可以参考深入理解SPARK SQL 中HashAggregateExec和ObjectHashAggregateExec以及UnsafeRow,该文可以比较清楚的解释ObjectHashAggregate和HashAggregate的区别:
- ObjectHashAggregate能够弥补HashAggregate 不能支持collect_set等这种表达式,从而不会转变为SortAggregate
- ObjectHashAggregate利用的是java Array对象(SpecificInternalRow)保存聚合的中间缓冲区,这对jvm gc是不太友好的
- ObjectHashAggregate根据hashMap的size(默认是128),而不是输入的行数来进行spill,这会导致提前spill,内存利用率不高。
- 由于提前的spill,ObjectHashAggregate会对剩下的所有数据做额外的一次排序操作(如果没有spill,就不需要额外的sort操作),而HashAggregate则是会对每次需要spill的数据做排序
使用jvm heap的内存使用情况以及处理的行数来指导什么时候开始spill。
但是这种在数据倾斜的情况下,会增加OOM的风险。
SortAggregate优化
目前SortAggreaget的现状是:
- 每个任务在sort Aggreate前需要按照key进行排序
- 根据排序的结果,在相邻的行之间进行聚合操作
不同于Hash Aggregate: - 不需要hashTable,也就不存在内存溢写和回退到sortAggregate
- 优化器更喜欢选择hashAggregate
- 没有codegen的实现.
目前在spark 3.3.0增加的功能:
- 如果数据是有序的话,会选择用sortAggragate替代HashAggregate
通过物理计划RuleReplaceHashWithSortAgg来做替换,当然通过spark.sql.execution.replaceHashWithSortAgg来开启(默认是关闭的),因为对于任何新特性,在release版本默认都是关闭的,在master分支才是开启的 - 支持sortAggretate(without keys)的codegen代码生成
其他
对于Aggregate更多的细节了解可以参考sparksql源码系列 | 一文搞懂with one count distinct 执行原理
边栏推荐
- 45. [Application of list linked list]
- How to import game archives in joiplay emulator
- C# VSCode & Rider引用命名空间快捷键
- 测试人面试 常被问到的计算机网络题,高薪回答模板来了
- H5跳转微信公众号解决方案
- asser利用蚁剑登录
- pytorch的安装注意事项
- Steven Giesel 最近发布了一个由5部分内容组成的系列,记录了他首次使用 Uno Platform 构建应用程序的经验。
- How to solve the error of joiplay simulator
- transition transition && animation animation
猜你喜欢
随机推荐
xss绕过:prompt(1)
Point Cloud Scene Reconstruction with Depth Estimation
ABC 261 F - Sorting Color Balls(逆序对)
Debezium error series 20: task failed to create new topic. Ensure that the task is authorized to create topics
第一个独立完成的千万级项目
Game mall table establishment
flex布局父项常见属性flex-wrap
Soft Exam Study Plan
An easy-to-use interface testing tools - the Postman
The first level must project independently
"Wei cup" school more than 2022 cattle summer camp 4 L.B lack Hole, computational geometry
leetcode(刷题篇13)
jira是什么
2022 China Logistics Industry Conference and Entrepreneur Summit Forum will be held in Hangzhou!
JS中? ?和??=和?.和 ||的区别
joiplay模拟器报错如何解决
实验8(vlan实验)
transition transition && animation animation
10 个关于自动化发布管理的好处
数据清洗-使用es的ingest









