簡體   English   中英

工人之間的RDD分區均衡-Spark

[英]Balanced RDD partition among workers - Spark

我正在使用x: key, y: set(values)RDD稱為file

#values: RDD of tuples (key, val)    
file = values.groupByKey().mapValues(set).cache()
info_file = array(file.map(lambda (x,y): len(y)).collect())
var = np.var(info_file) #extremely high
def f():
     ...
file.foreachPartition(f)

len(y)的方差非常大,以致於約有1%的對對集合(已通過百分位數方法驗證)使集合中值總數的20%成為total = np.sum(info_file) 如果Spark隨機隨機分配分區,則很有可能1%可能落在同一分區中,從而使工作人員之間的負載不均衡。

有沒有辦法確保“重”元組在分區之間相等地分配? 我實際上根據閾值threshold = np.percentile(info_file,99.9)給出的len(y)閾值,將file分成了heavylight兩個分區,以便分離這組元組,然后重新分區。

light = file.filter(lambda (x,y): len(y) < threshold).cache()
heavy = file.filter(lambda (x,y): len(y) >= threshold).cache()

light.foreachPartition(f)
heavy.foreachPartition(f)

但獲得幾乎相同的運行時間。 負載可能已經優化,只想檢查我是否可以做更多/更好的事情。

您可以使用Ganglia監視群集負載。 這樣可以很好地指示可能導致群集負載不均勻的任何數據偏斜。

如果您確實有不幸的數據偏斜,則可以通過一些方法來解決它,例如重組數據或添加鹽鍵。 例如,參見此StackOverflow問答

請注意,您也可以做,你現在在做什么,用數據分割成heavy分區和light分區,但在這種情況下,你要cachefile -不heavylight -因為它是file ,你需要處理多次。 像這樣:

cachedFile = file.cache()

light = cachedFile.filter(lambda (x,y): len(y) < threshold)
heavy = cachedFile.filter(lambda (x,y): len(y) >= threshold)

light.foreachPartition(f)
heavy.foreachPartition(f)

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM