|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.spark.sql.benchmark |
| 21 | + |
| 22 | +import org.apache.spark.SparkConf |
| 23 | +import org.apache.spark.sql.SparkSession |
| 24 | +import org.apache.spark.sql.internal.SQLConf |
| 25 | + |
| 26 | +import org.apache.comet.{CometConf, CometSparkSessionExtensions} |
| 27 | + |
| 28 | +/** |
| 29 | + * Benchmark to measure performance of Comet BroadcastNestedLoopJoin. To run this benchmark: |
| 30 | + * {{{ |
| 31 | + * SPARK_GENERATE_BENCHMARK_FILES=1 make benchmark-org.apache.spark.sql.benchmark.CometBroadcastNestedLoopJoinBenchmark |
| 32 | + * }}} |
| 33 | + * Results will be written to |
| 34 | + * "spark/benchmarks/CometBroadcastNestedLoopJoinBenchmark-**results.txt". |
| 35 | + */ |
| 36 | +object CometBroadcastNestedLoopJoinBenchmark extends CometBenchmarkBase { |
| 37 | + |
| 38 | + override def getSparkSession: SparkSession = { |
| 39 | + val conf = new SparkConf() |
| 40 | + .setAppName("CometBroadcastNestedLoopJoinBenchmark") |
| 41 | + .set("spark.master", "local[5]") |
| 42 | + .setIfMissing("spark.driver.memory", "3g") |
| 43 | + .setIfMissing("spark.executor.memory", "3g") |
| 44 | + .set( |
| 45 | + "spark.shuffle.manager", |
| 46 | + "org.apache.spark.sql.comet.execution.shuffle.CometShuffleManager") |
| 47 | + |
| 48 | + val sparkSession = SparkSession.builder |
| 49 | + .config(conf) |
| 50 | + .withExtensions(new CometSparkSessionExtensions) |
| 51 | + .getOrCreate() |
| 52 | + |
| 53 | + sparkSession.conf.set(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key, "true") |
| 54 | + sparkSession.conf.set(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key, "true") |
| 55 | + sparkSession.conf.set(CometConf.COMET_ENABLED.key, "false") |
| 56 | + sparkSession.conf.set(CometConf.COMET_EXEC_ENABLED.key, "false") |
| 57 | + sparkSession.conf.set(SQLConf.ANSI_ENABLED.key, "false") |
| 58 | + sparkSession.conf.set("spark.sql.shuffle.partitions", "2") |
| 59 | + |
| 60 | + sparkSession |
| 61 | + } |
| 62 | + |
| 63 | + private val cometConfigs: Map[String, String] = Map.empty[String, String] |
| 64 | + |
| 65 | + override def runCometBenchmark(mainArgs: Array[String]): Unit = { |
| 66 | + val probeRows = 1024 * 1024 |
| 67 | + val buildRows = 100 |
| 68 | + |
| 69 | + withTempPath { dir => |
| 70 | + withTempTable("probe", "build") { |
| 71 | + spark |
| 72 | + .range(probeRows) |
| 73 | + .selectExpr("id AS k", "id % 100 AS v") |
| 74 | + .write |
| 75 | + .parquet(s"${dir.getAbsolutePath}/probe") |
| 76 | + spark |
| 77 | + .range(buildRows) |
| 78 | + .selectExpr("id * 1000 AS lo", "id * 1000 + 500 AS hi") |
| 79 | + .write |
| 80 | + .parquet(s"${dir.getAbsolutePath}/build") |
| 81 | + |
| 82 | + spark.read.parquet(s"${dir.getAbsolutePath}/probe").createOrReplaceTempView("probe") |
| 83 | + spark.read.parquet(s"${dir.getAbsolutePath}/build").createOrReplaceTempView("build") |
| 84 | + |
| 85 | + runBenchmark("BroadcastNestedLoopJoin - range") { |
| 86 | + runExpressionBenchmark( |
| 87 | + "range join (BETWEEN)", |
| 88 | + probeRows, |
| 89 | + "SELECT count(*) FROM probe p " + |
| 90 | + "JOIN build b ON p.k BETWEEN b.lo AND b.hi", |
| 91 | + cometConfigs) |
| 92 | + } |
| 93 | + |
| 94 | + runBenchmark("BroadcastNestedLoopJoin - inequality") { |
| 95 | + runExpressionBenchmark( |
| 96 | + "inequality join (>)", |
| 97 | + probeRows, |
| 98 | + "SELECT count(*) FROM probe p " + |
| 99 | + "JOIN build b ON p.k > b.lo", |
| 100 | + cometConfigs) |
| 101 | + } |
| 102 | + |
| 103 | + runBenchmark("BroadcastNestedLoopJoin - left outer with non-equi") { |
| 104 | + runExpressionBenchmark( |
| 105 | + "left outer non-equi", |
| 106 | + probeRows, |
| 107 | + "SELECT count(*) FROM probe p " + |
| 108 | + "LEFT OUTER JOIN build b ON p.k BETWEEN b.lo AND b.hi", |
| 109 | + cometConfigs) |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | +} |
0 commit comments