spark-sql-perf
文章目錄
- 簡介
- 測試
- tpcds-kit
- spark-sql-perf
- 生成數據
- 執行查詢
- 查詢結果
- TPC-DS
- FAQ
簡介
spark-sql-perf 是一個 spark sql 性能測試框架,可以用來進行一些基準測試。
測試環境:
- spark 2.4.0
- spark-sql-perf_2.11-0.5.0-SNAPSHOT
測試
tpcds-kit
通過 tpcds-kit 生成 TPC-DS 數據。
sudo yum install gcc make flex bison byacc git git clone https://github.com/databricks/tpcds-kit.git cd tpcds-kit/tools make OS=LINUXspark-sql-perf
編譯打包,從$spark-sql-perf/target/scala-2.11 下獲得需要的jar包(spark-sql-perf_2.11-0.5.0-SNAPSHOT.jar)
git clone https://github.com/databricks/spark-sql-perf.git sbt package啟動 spark-shell
spark-shell \--conf spark.executor.instances=40 \--conf spark.executor.cores=3 \--conf spark.executor.memory=8g \--conf spark.executor.memoryOverhead=2g \--jars scala-logging-slf4j_2.11-2.1.2.jar,scala-logging-api_2.11-2.1.2.jar,spark-sql-perf_2.11-0.5.0-SNAPSHOT.jar生成數據
需要提前將 tpcds-kit 分發到所有 spark executor 節點
import com.databricks.spark.sql.perf.tpcds.TPCDSTablesval rootDir = "hdfs://ns/user/admin/tpcds/data" val dsdgenDir = "/path/to/tpcds-kit/tools" val scaleFactor = "20" val format = "parquet" val databaseName = "tpcds"val sqlContext = spark.sqlContext val tables = new TPCDSTables(sqlContext,dsdgenDir = dsdgenDir, scaleFactor = scaleFactor,useDoubleForDecimal = true, useStringForDate = true)tables.genData(location = rootDir,format = format,overwrite = true,partitionTables = true, clusterByPartitionColumns = true, filterOutNullPartitionValues = false, tableFilter = "", numPartitions = 120)//創建臨時表 tables.createTemporaryTables(rootDir, format) //將表信息注冊到 hive metastore //sql(s"create database $databaseName") //tables.createExternalTables(rootDir, format, databaseName, overwrite = true, discoverPartitions = true)執行查詢
默認情況下,使用 runExperiment 會在后臺線程中進行,最終將結果以JSON格式保存到 resultLocation 下時間戳命名的子目錄中,例如 $resultLocation/timestamp=1429213883272
import com.databricks.spark.sql.perf.tpcds.TPCDSval tpcds = new TPCDS (sqlContext) val databaseName = "tpcds" sql(s"use $databaseName")val resultLocation = "hdfs://ns/user/admin/result" val iterations = 1 val queries = tpcds.tpcds2_4Queries //單個查詢設置超時時間 val timeout = 300val experiment = tpcds.runExperiment(queries, iterations = iterations,resultLocation = resultLocation,forkThread = true) experiment.waitForFinish(timeout)查詢結果
有兩種獲取方式,如果 experiment 還沒有關閉,可以使用 experiment.getCurrentResults 方法獲取
//從 experiment 獲取結果 experiment.getCurrentResults. withColumn("Name", substring(col("name"), 2, 100)). withColumn("Runtime", (col("parsingTime") + col("analysisTime") + col("optimizationTime") + col("planningTime") + col("executionTime")) / 1000.0). selectExpr('Name, 'Runtime)如果已經關閉,則可以從 resultLocation 中獲取結果JSON文件并解析
//從文件中讀取 val result = spark.read.json(resultLocation) result.select("results.name","results.executionTime").flatMap(r=>{val name = r.getAs[Seq[String]]("name")val executionTime = r.getAs[Seq[Double]]("executionTime")name.zip(executionTime) }).toDF("name","executionTime").show()TPC-DS
TPC-DS采用星型、雪花型等多維數據模式。它包含7張事實表,17張緯度表平均每張表含有18列。其工作負載包含99個SQL查詢,覆蓋SQL99和2003的核心部分以及OLAP。這個測試集包含對大數據集的統計、報表生成、聯機查詢、數據挖掘等復雜應用,測試用的數據和值是有傾斜的,與真實數據一致。可以說TPC-DS是與真實場景非常接近的一個測試集,也是難度較大的一個測試集。
TPC-DS的這個特點跟大數據的分析挖掘應用非常類似。Hadoop等大數據分析技術也是對海量數據進行大規模的數據分析和深度挖掘,也包含交互式聯機查詢和統計報表類應用,同時大數據的數據質量也較低,數據分布是真實而不均勻的。因此TPC-DS成為客觀衡量多個不同Hadoop版本以及SQL on Hadoop技術的最佳測試集。這個基準測試有以下幾個主要特點:
- 一共99個測試案例,遵循SQL’99和SQL 2003的語法標準,SQL案例比較復雜
- 分析的數據量大,并且測試案例是在回答真實的商業問題
- 測試案例中包含各種業務模型(如分析報告型,迭代式的聯機分析型,數據挖掘型等)
- 幾乎所有的測試案例都有很高的IO負載和CPU計算需求
FAQ
執行 new TPCDS 時如果提示
java.lang.ClassNotFoundException: com.typesafe.scalalogging.slf4j.LazyLogging java.lang.ClassNotFoundException: com.typesafe.scalalogging.Logging導入相應的包即可
--jars /path/to/scala-logging-slf4j_2.11-2.1.2.jar,/path/to/scala-logging-api_2.11-2.1.2.jar總結
以上是生活随笔為你收集整理的spark-sql-perf的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大数据、互联网、机器人成大热门
- 下一篇: 网易杭研 java 校招_09网易杭研校