1.使用reduceByKey/aggregateByKey替代groupByKey
2.使用mapPartitions替代普通map
3.使用foreachPartitions替代foreach
4.使用filter之后进行coalesce操作
5.使用repartitionAndSortWithinPartitions替代repartition与sort类操作
6.使用broadcast使各task共享同一Executor的集合替代算子函数中各task传送一份集合
7.使用相同分区方式的join可以避免Shuffle
8.map和flatMap选择
9.cache和persist选择
10.zipWithIndex和zipWithUniqueId选择
1.使用reduceByKey/aggregateByKey替代groupByKey
reduceByKey/aggregateByKey底层使用combinerByKey实现,会在map端进行局部聚合;groupByKey不会。
map端预聚合的算子: reduceByKey/aggregateByKey/combinerByKey
使用map-side预聚合的shuffle操作,尽量使用有combiner的shuffle类算子。
combiner概念:
在map端,每一