This is an automated email from the ASF dual-hosted git repository.
ulyssesyou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 627d271 [KYUUBI #1167] Add zorder core benchmark
627d271 is described below
commit 627d271fc6de45bf4bc4bbd9f630b29c8beabed9
Author: ulysses-you <[email protected]>
AuthorDate: Tue Sep 28 09:24:19 2021 +0800
[KYUUBI #1167] Add zorder core benchmark
<!--
Thanks for sending a pull request!
Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://kyuubi.readthedocs.io/en/latest/community/contributions.html
2. If the PR is related to an issue in
https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your
PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g.,
'[WIP][KYUUBI #XXXX] Your PR title ...'.
-->
### _Why are the changes needed?_
<!--
Please clarify why the changes are needed. For instance,
1. If you add a feature, you can talk about the use case of it.
2. If you fix a bug, you can clarify why it is a bug.
-->
Add zorder core benchmark, so we can get the perf number of zorder.
This PR adds two column type `int` and `long` benchmark:
- 2 int cols
- 3 int cols
- 4 int cols
- 2 long cols
- 3 long cols
- 4 long cols
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including
negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [x] [Run
test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests)
locally before make a pull request
Closes #1167 from ulysses-you/benchmark.
Closes #1167
27ecf51f [ulysses-you] Add zorder core benchmark
Authored-by: ulysses-you <[email protected]>
Signed-off-by: ulysses-you <[email protected]>
---
.../benchmarks/ZorderCoreBenchmark-results.txt | 11 +++
.../org/apache/spark/sql/ZorderCoreBenchmark.scala | 87 ++++++++++++++++++++++
.../spark/sql/benchmark/KyuubiBenchmarkBase.scala | 71 ++++++++++++++++++
pom.xml | 1 +
4 files changed, 170 insertions(+)
diff --git
a/dev/kyuubi-extension-spark-3-1/benchmarks/ZorderCoreBenchmark-results.txt
b/dev/kyuubi-extension-spark-3-1/benchmarks/ZorderCoreBenchmark-results.txt
new file mode 100644
index 0000000..b0e24d2
--- /dev/null
+++ b/dev/kyuubi-extension-spark-3-1/benchmarks/ZorderCoreBenchmark-results.txt
@@ -0,0 +1,11 @@
+Java HotSpot(TM) 64-Bit Server VM 1.8.0_271-b09 on Mac OS X 10.16
+Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
+1000000 rows zorder core benchmark: Best Time(ms) Avg Time(ms)
Stdev(ms) Rate(M/s) Per Row(ns) Relative
+------------------------------------------------------------------------------------------------------------------------
+2 int columns benchmark 1782 1846
60 0.6 1781.8 1.0X
+3 int columns benchmark 1570 1751
205 0.6 1570.2 1.1X
+4 int columns benchmark 1867 1957
83 0.5 1867.2 1.0X
+2 long columns benchmark 2442 2479
35 0.4 2441.7 0.7X
+3 long columns benchmark 2891 3181
252 0.3 2891.5 0.6X
+4 long columns benchmark 3475 3524
81 0.3 3474.6 0.5X
+
diff --git
a/dev/kyuubi-extension-spark-3-1/src/test/scala/org/apache/spark/sql/ZorderCoreBenchmark.scala
b/dev/kyuubi-extension-spark-3-1/src/test/scala/org/apache/spark/sql/ZorderCoreBenchmark.scala
new file mode 100644
index 0000000..265bd41
--- /dev/null
+++
b/dev/kyuubi-extension-spark-3-1/src/test/scala/org/apache/spark/sql/ZorderCoreBenchmark.scala
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql
+
+import org.apache.spark.benchmark.Benchmark
+import org.apache.spark.sql.benchmark.KyuubiBenchmarkBase
+
+import org.apache.kyuubi.sql.zorder.ZorderBytesUtils
+
+// scalastyle:off line.size.limit
+/**
+ * Benchmark to measure performance with zorder core.
+ *
+ * To run this benchmark:
+ * {{{
+ * ./build/mvn -Dtest=none -pl
'!externals/kyuubi-download,!dev/kyuubi-codecov,!kyuubi-assembly,!kyuubi-server,!kyuubi-zookeeper,!kyuubi-hive-jdbc,!kyuubi-ha,!externals/kyuubi-spark-monitor,!kyuubi-common,!externals/kyuubi-spark-sql-engine,!kyuubi-ctl,!kyuubi-metrics'
-Pspark-3.1 -DwildcardSuites=org.apache.spark.sql.ZorderCoreBenchmark
-Pkyuubi-extension-spark-3-1 test
+ * }}}
+ */
+// scalastyle:on line.size.limit
+class ZorderCoreBenchmark extends KyuubiSparkSQLExtensionTest with
KyuubiBenchmarkBase {
+ private val numRows = 1 * 1000 * 1000
+
+ private def randomIntByteArray(numColumns: Int): Seq[Array[Array[Byte]]] = {
+ (1 to numRows).map { i =>
+ val arr = new Array[Array[Byte]](numColumns)
+ (0 until numColumns).foreach(col => arr(col) =
ZorderBytesUtils.toByte(i))
+ arr
+ }
+ }
+
+ private def randomLongByteArray(numColumns: Int): Seq[Array[Array[Byte]]] = {
+ (1 to numRows).map { i =>
+ val l = i.toLong
+ val arr = new Array[Array[Byte]](numColumns)
+ (0 until numColumns).foreach(col => arr(col) =
ZorderBytesUtils.toByte(l))
+ arr
+ }
+ }
+
+ ignore("zorder core benchmark") {
+ withHeader {
+ val benchmark = new Benchmark(
+ s"$numRows rows zorder core benchmark", numRows, output = output)
+ benchmark.addCase("2 int columns benchmark", 3) { _ =>
+
randomIntByteArray(2).foreach(ZorderBytesUtils.interleaveMultiByteArray)
+ }
+
+ benchmark.addCase("3 int columns benchmark", 3) { _ =>
+
randomIntByteArray(3).foreach(ZorderBytesUtils.interleaveMultiByteArray)
+ }
+
+ benchmark.addCase("4 int columns benchmark", 3) { _ =>
+
randomIntByteArray(4).foreach(ZorderBytesUtils.interleaveMultiByteArray)
+ }
+
+
+ benchmark.addCase("2 long columns benchmark", 3) { _ =>
+
randomLongByteArray(2).foreach(ZorderBytesUtils.interleaveMultiByteArray)
+ }
+
+ benchmark.addCase("3 long columns benchmark", 3) { _ =>
+
randomLongByteArray(3).foreach(ZorderBytesUtils.interleaveMultiByteArray)
+ }
+
+ benchmark.addCase("4 long columns benchmark", 3) { _ =>
+
randomLongByteArray(4).foreach(ZorderBytesUtils.interleaveMultiByteArray)
+ }
+
+ benchmark.run()
+ }
+ }
+}
diff --git
a/dev/kyuubi-extension-spark-3-1/src/test/scala/org/apache/spark/sql/benchmark/KyuubiBenchmarkBase.scala
b/dev/kyuubi-extension-spark-3-1/src/test/scala/org/apache/spark/sql/benchmark/KyuubiBenchmarkBase.scala
new file mode 100644
index 0000000..de440e7
--- /dev/null
+++
b/dev/kyuubi-extension-spark-3-1/src/test/scala/org/apache/spark/sql/benchmark/KyuubiBenchmarkBase.scala
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.benchmark
+
+import java.io.{File, FileOutputStream, OutputStream}
+
+import scala.collection.JavaConverters._
+
+import com.google.common.reflect.ClassPath
+
+trait KyuubiBenchmarkBase {
+ var output: Option[OutputStream] = None
+
+ private val prefix = {
+ val benchmarkClasses = ClassPath.from(
+ Thread.currentThread.getContextClassLoader
+ ).getTopLevelClassesRecursive("org.apache.spark.sql").asScala.toArray
+ assert(benchmarkClasses.nonEmpty)
+ val benchmark =
benchmarkClasses.find(_.load().getName.endsWith("Benchmark"))
+ val targetDirOrProjDir =
+ new
File(benchmark.get.load().getProtectionDomain.getCodeSource.getLocation.toURI)
+ .getParentFile.getParentFile
+ if (targetDirOrProjDir.getName == "target") {
+ targetDirOrProjDir.getParentFile.getCanonicalPath + "/"
+ } else {
+ targetDirOrProjDir.getCanonicalPath + "/"
+ }
+ }
+
+ def withHeader(func: => Unit): Unit = {
+ val version = System.getProperty("java.version").split("\\D+")(0).toInt
+ val jdkString = if (version > 8) s"-jdk$version" else ""
+ val resultFileName =
+ s"${this.getClass.getSimpleName.replace("$", "")}$jdkString-results.txt"
+ val dir = new File(s"${prefix}benchmarks/")
+ if (!dir.exists()) {
+ // scalastyle:off println
+ println(s"Creating ${dir.getAbsolutePath} for benchmark results.")
+ // scalastyle:on println
+ dir.mkdirs()
+ }
+ val file = new File(dir, resultFileName)
+ if (!file.exists()) {
+ file.createNewFile()
+ }
+ output = Some(new FileOutputStream(file))
+
+ func
+
+ output.foreach { o =>
+ if (o != null) {
+ o.close()
+ }
+ }
+ }
+}
diff --git a/pom.xml b/pom.xml
index 69933e1..64c0c59 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1744,6 +1744,7 @@
<exclude>**/**/operation_logs/**/**</exclude>
<exclude>**/*.output.schema</exclude>
<exclude>**/apache-kyuubi-*-bin*/**</exclude>
+ <exclude>**/benchmarks/**</exclude>
</excludes>
</configuration>
</plugin>