def naive_word_counting(wordsList):
words = {}
for word in wordsList:
if word in words:
words[word] = 1
else:
words[word] = 1
return sorted(words.items(), key=lambda x: x[1], reverse=True)
def map_reduce_word_counting(wordsList):
sparkRDD = sparkEngine.sparkContext.parallelize(wordsList)
def map_function(word):
return (word, 1)
def reduce_function(a, b):
return a b
counts = sparkRDD.map(map_function).reduceByKey(reduce_function)
return counts.sortBy(lambda x: x[1], ascending=False).collect()
在 4.141.822 個單詞的串列中,naive_word_counting runs在 0.61 秒內運行,而在 3.01 秒內map_reduce_word_counting運行。我預計 spark 會比原生方式更快,但它確實慢得多。
為什么會這樣?有什么我不明白的嗎?
uj5u.com熱心網友回復:
您如何僅通過字數來衡量這部分的執行時間?請記住,在執行主邏輯之前,Spark 需要一些時間來創建背景關系。
請找到另一個如何計算字數的示例: https ://bigdata-etl.com/configuration-of-apache-spark-scala-and-intellij/
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/463336.html
上一篇:hive的磁區策略
