forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-25710][SQL] range should report metrics correctly
## What changes were proposed in this pull request? Currently `Range` reports metrics in batch granularity. This is acceptable, but it's better if we can make it row granularity without performance penalty. Before this PR, the metrics are updated when preparing the batch, which is before we actually consume data. In this PR, the metrics are updated after the data are consumed. There are 2 different cases: 1. The data processing loop has a stop check. The metrics are updated when we need to stop. 2. no stop check. The metrics are updated after the loop. ## How was this patch tested? existing tests and a new benchmark Closes apache#22698 from cloud-fan/range. Authored-by: Wenchen Fan <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
- Loading branch information
Showing
4 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
================================================================================================ | ||
range | ||
================================================================================================ | ||
|
||
Java HotSpot(TM) 64-Bit Server VM 1.8.0_161-b12 on Mac OS X 10.13.6 | ||
Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz | ||
|
||
range: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative | ||
------------------------------------------------------------------------------------------------ | ||
full scan 12674 / 12840 41.4 24.2 1.0X | ||
limit after range 33 / 37 15900.2 0.1 384.4X | ||
filter after range 969 / 985 541.0 1.8 13.1X | ||
count after range 42 / 42 12510.5 0.1 302.4X | ||
count after limit after range 32 / 33 16337.0 0.1 394.9X | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/RangeBenchmark.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.execution.benchmark | ||
|
||
import org.apache.spark.benchmark.Benchmark | ||
|
||
/** | ||
* Benchmark to measure performance for range operator. | ||
* To run this benchmark: | ||
* {{{ | ||
* 1. without sbt: | ||
* bin/spark-submit --class <this class> --jars <spark core test jar> <spark sql test jar> | ||
* 2. build/sbt "sql/test:runMain <this class>" | ||
* 3. generate result: SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain <this class>" | ||
* Results will be written to "benchmarks/RangeBenchmark-results.txt". | ||
* }}} | ||
*/ | ||
object RangeBenchmark extends SqlBasedBenchmark { | ||
|
||
override def runBenchmarkSuite(): Unit = { | ||
import spark.implicits._ | ||
|
||
runBenchmark("range") { | ||
val N = 500L << 20 | ||
val benchmark = new Benchmark("range", N, output = output) | ||
|
||
benchmark.addCase("full scan", numIters = 4) { _ => | ||
spark.range(N).queryExecution.toRdd.foreach(_ => ()) | ||
} | ||
|
||
benchmark.addCase("limit after range", numIters = 4) { _ => | ||
spark.range(N).limit(100).queryExecution.toRdd.foreach(_ => ()) | ||
} | ||
|
||
benchmark.addCase("filter after range", numIters = 4) { _ => | ||
spark.range(N).filter('id % 100 === 0).queryExecution.toRdd.foreach(_ => ()) | ||
} | ||
|
||
benchmark.addCase("count after range", numIters = 4) { _ => | ||
spark.range(N).count() | ||
} | ||
|
||
benchmark.addCase("count after limit after range", numIters = 4) { _ => | ||
spark.range(N).limit(100).count() | ||
} | ||
|
||
benchmark.run() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters