![](/img/trans.png)
[英]How to set dynamic spark.sql.shuffle.partitions in pyspark?
[英]How to dynamically choose spark.sql.shuffle.partitions
我目前正在處理使用火花和foreach分區開到MySQL的連接,並將其插入到一批1000數據庫中的數據正如提到SparkDocumentation的默認值spark.sql.shuffle.partitions
是200,但我想保持它充滿活力。 那么,我該如何計算呢。 因此,既沒有選擇非常高的值導致性能下降也沒有選擇非常小的值導致OOM
。
嘗試以下選項 -
val numExecutors = spark.conf.get("spark.executor.instances").toInt
val numExecutorsCores = spark.conf.get("spark.executor.cores").toInt
val numShufflePartitions = (numExecutors * numExecutorsCores)
spark.conf.set("spark.sql.shuffle.partitions", numShufflePartitions)
這將幫助您根據用於spark作業的執行程序和執行程序核心設置正確數量的隨機分區,而不會影響性能並導致內存不足問題。
如果你仍然離開了記憶,他們設置在下面的財產 -
spark.conf.set("spark.executor.memoryOverhead", "3G")
其他選項是計算數據Dataframe
大小, didvie
hdfs
塊大小執行,並使用結果數設置spark.sql.shuffle.partitions
。
您可以使用df.repartition(numPartitions)方法執行此操作。 您可以根據輸入/中間輸出做出決定,並將numPartitions傳遞給repartition()方法。
df.repartition(numPartitions) or rdd.repartition(numPartitions)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.