Spark中的spark.sql.shuffle.partitions 和spark.default.parallelism参数设置默认partition数目

当不跟随父对象partition数目的shuffle过程发生后,结果的partition会发生改变,这两个参数就是控制这类shuffle过程后,返回对象的partition的

经过实测,得到结论:

spark.sql.shuffle.partitions 作用于dataframe(val df2=df1.shuffle算子(如df1.orderBy()),的df2的partition就是这个参数的值)

spark.default.parallelism 作用于rdd(val rdd2=rdd1.shuffle算子(如rdd1.reduceByKey()),的rdd2的partition就是这个参数的值)

如何查看操作是否有shuffle?善用rdd的toDebugString函数,详见Spark中的shuffle算子

df也可以先df.rdd.toDebugString查看是否有shuffle发生

另外,也可以说:

  • spark.default.parallelism只有在处理RDD时有效。
  • spark.sql.shuffle.partitions则是只对SparkSQL(产生的是dataframe)有效。

修改方法:

代码中设定:

sqlContext.setConf("spark.sql.shuffle.partitions", "500")
sqlContext.setConf("spark.default.parallelism", "500")

提交任务时设定:

./bin/spark-submit --conf spark.sql.shuffle.partitions=500 --conf spark.default.parallelism=500

官方说明和默认值:

spark.default.parallelismFor distributed shuffle operations like reduceByKey and join, the largest number of partitions in a parent RDD. For operations like parallelize with no parent RDDs, it depends on the cluster manager:
  • Local mode: number of cores on the local machine
  • Mesos fine grained mode: 8
  • Others: total number of cores on all executor nodes or 2, whichever is larger
Default number of partitions in RDDs returned by transformations like joinreduceByKey, and parallelize when not set by user.
spark.sql.shuffle.partitions200(default)

Configures the number of partitions to use when shuffling data for joins or aggregations. 

该参数也决定着sc.sql(...)取数据时的并行度

跟随父对象partition数目的shuffle?比如df的join,df1.join(df2) 返回partition数目根据df1定




参考资料:

Configuration - Spark 2.1.0 Documentation

Performance Tuning - Spark 3.4.0 Documentation

https://www.jianshu.com/p/7442deb21ae0

performance - What is the difference between spark.sql.shuffle.partitions and spark.default.parallelism? - Stack Overflow

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值