【问题标题】:Spark K-means Performance Decreases with More Nodes/InstancesSpark K-means 性能随着节点/实例的增加而降低
【发布时间】:2020-02-19 04:25:23
【问题描述】:

我正在使用 Spark MLLib 在 AWS EMR 上执行 K-means 集群。数据集大约为 10^6 行,包含 9 个特征列。我使用的实例大小有 8vCPU 和 32GB 内存。

我预计随着集群上节点数量的增加,我会从 Spark 中提高性能(减少执行时间),但是我得到了相反的结果。

与使用单个工作节点相比,使用更多工作节点/实例的性能更差(执行时间更长)。对于 5、10 和 15 个工作节点的集群,我得到了相同的结果;随着节点数量的增加,性能会下降。我尝试改变分区 (spark.sql.shuffle.partitions) 并使用执行器核心、执行器数量和执行器内存的各种配置。

我的代码如下(执行器数量为 10 个工作节点):

spark-shell --executor-cores 3 num-executors 20 --executor-memory 10G

import org.apache.hadoop.conf.Configuration
import org.apache.phoenix.spark._ 
import org.apache.spark.sql.functions._
import org.apache.spark.ml.clustering.KMeans
import org.apache.spark.ml.feature.VectorAssembler
import org.apache.spark.ml.feature.MinMaxScaler
import org.apache.spark.sql.{SparkSession, SQLContext, DataFrame}
import org.apache.spark.{SparkConf, SparkContext} 
import org.apache.spark.ml.linalg.{Vector, Vectors, DenseVector, VectorUDT}
import org.apache.spark.ml.linalg._
import org.apache.spark.sql.types.{StructField, StructType}
import org.apache.spark.mllib.linalg.{Vector, Vectors, DenseVector, SparseVector}

sc.stop()
val configuration = new Configuration()
val sc = new SparkContext("local", "phoenix-load")
val sqlContext = new SQLContext(sc) 

//dataset is loaded in from Phoenix table and set as featureDf6
//dataset is made up of all numerical values (DOUBLE)

val columns = Array("DUR","AVG_AMP","AVG_POW","PAPR","SNR","SNR_DB","BW_3DB","BW_10DB","BWNE")    
val assembler = new VectorAssembler().setInputCols(columns).setOutputCol("featuresin")
val df = assembler.transform(featureDf6)

val scaler = new MinMaxScaler().setInputCol("featuresin").setOutputCol("features").setMin(-1).setMax(1)
val scalerModel = scaler.fit(df)
val scaledData = scalerModel.transform(df)

val kmeans = new KMeans().setK(14).setSeed(1L).setMaxIter(1000)
val model = kmeans.fit(scaledData)

【问题讨论】:

  • 您的数据有多大?您的节点/执行器数量应与您的数据大小一致,否则 spark 将花费时间只是对数据进行洗牌,这也涉及网络延迟
  • 我运行了 70MB、1.6GB 和 16GB 的数据集,具有不同数量的节点(1、5、10、15),并将执行器的数量扩展到每个节点 2 个。

标签: apache-spark apache-spark-sql k-means apache-spark-mllib amazon-emr


【解决方案1】:

我发现问题的原因是 Spark 从 Phoenix/HBase 读取数据的方法。当我将数据集直接上传到 Spark 时,结果符合预期,并且随着节点的增加,执行时间下降。我将发布另一个问题,以识别从 Phoenix 读取过程中的错误。

【讨论】:

    猜你喜欢
    • 2018-09-22
    • 2020-09-02
    • 2018-06-08
    • 2019-09-17
    • 2019-04-14
    • 2017-10-17
    • 1970-01-01
    • 2017-08-21
    • 2017-10-07
    相关资源
    最近更新 更多