繁体   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