簡體   English   中英

在 Apache Spark 中,當增加工人數量時,對於一些小數據集無法達到更好的加速

[英]Can not reach better speed up in Apache Spark for some small datasets when increase the number of workers

我使用 Spark 使用隨機森林算法對人口普查收入數據集進行分類。 我的工人(w1 和 w2)有一個 CPU(4 核)。 當我將 Spark 配置為僅使用 w1 作為 worker 時,構建 model 大約需要 12 秒。 當我將 Spark 配置為同時使用 w1 和 w2 作為 worker 時,構建 model 再次需要 12 秒。 我可以通過“htop”看到,當我運行代碼時,兩個工作人員的 CPU 使用率都很高。 但是,當我使用更大的數據集時,我希望達到更低的執行時間。 我可以達到更少的執行時間。

這是我的代碼片段:

import org.apache.spark.mllib.tree.RandomForest
import org.apache.spark.mllib.tree.model.RandomForestModel
import org.apache.spark.mllib.util.MLUtils

// Load and parse the data file.
val data = MLUtils.loadLibSVMFile(sc, "data/Census-income.libsvm")
// Split the data into training and test sets (30% held out for testing)
val splits = data.randomSplit(Array(0.7, 0.3))
val (trainingData, testData) = (splits(0), splits(1))

// Train a RandomForest model.
// Empty categoricalFeaturesInfo indicates all features are continuous.
val numClasses = 2
val categoricalFeaturesInfo = Map[Int, Int]()
val numTrees = 3 // Use more in practice.
val featureSubsetStrategy = "auto" // Let the algorithm choose.
val impurity = "gini"
val maxDepth = 4
val maxBins = 32

val model = RandomForest.trainClassifier(trainingData, numClasses, categoricalFeaturesInfo,
numTrees, featureSubsetStrategy, impurity, maxDepth, maxBins)

// Evaluate model on test instances and compute test error
val labelAndPreds = testData.map { point =>
  val prediction = model.predict(point.features)
(point.label, prediction)
}
val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.count()
println(s"Test Error = $testErr")

問題是什么? 任何評論表示贊賞。

Amdahl 定律Gunther 定律都適用於此。

阿姆達爾定律本質上說,並行化的性能不能增加超過不可並行化的工作的相對部分的倒數(相對於總工作):如果一半的工作是可並行的,而另一半不是,那么添加一個無限數量的工人最多可以使可並行化的一半是瞬時的,但不可並行化的一半將保持不變:因此您基本上可以將速度提高一倍。

岡瑟定律反過來意味着每個增加的工人都會施加一些額外的爭用和一致性延遲:增加工人只有在增加的工人的收益超過這個非零的性能損失時才能提高性能。

在 Spark 作業中,有非零數量的不可並行化的工作(例如,為作業設置驅動程序)。 可並行化的工作量受數據集大小的限制:數據集越小,不可並行化的工作負載就越多。

此外,在 Spark 作業中完成的一些操作將導致爭用和一致性延遲,進一步降低了添加更多工作人員的好處(我對 Spark MLLib 是否執行此類操作沒有經驗)。

暫無
暫無

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

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