Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-25664][SQL][TEST] Refactor JoinBenchmark to use main method #22661

Closed
wants to merge 7 commits into from
Closed

[SPARK-25664][SQL][TEST] Refactor JoinBenchmark to use main method #22661

wants to merge 7 commits into from

Conversation

wangyum
Copy link
Member

@wangyum wangyum commented Oct 7, 2018

What changes were proposed in this pull request?

Refactor JoinBenchmark to use main method.

  1. use spark-submit:
bin/spark-submit --class  org.apache.spark.sql.execution.benchmark.JoinBenchmark --jars ./core/target/spark-core_2.11-3.0.0-SNAPSHOT-tests.jar ./sql/catalyst/target/spark-sql_2.11-3.0.0-SNAPSHOT-tests.jar
  1. Generate benchmark result:
SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain org.apache.spark.sql.execution.benchmark.JoinBenchmark"

How was this patch tested?

manual tests

@SparkQA
Copy link

SparkQA commented Oct 7, 2018

Test build #97080 has finished for PR 22661 at commit 4339b1c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 7, 2018

Test build #97090 has finished for PR 22661 at commit 4859a9f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum
Copy link
Member Author

wangyum commented Oct 9, 2018

cc @dongjoon-hyun

val N = 20 << 20
val M = 1 << 16

val dim = broadcast(sparkSession.range(M).selectExpr("id as k", "cast(id as string) as v"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is a removal of redundant one, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

val dim = broadcast(sparkSession.range(M).selectExpr("cast(id/10 as long) as k"))
val df = sparkSession.range(N).join(dim, (col("id") % M) === col("k"))
codegenBenchmark("Join w long duplicated", N) {
val dim = broadcast(spark.range(M).selectExpr("cast(id/10 as long) as k"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to another bechmark case in this file, broadcast seems to be put outside of codegenBenchmark. How do you think about this?

Join w 2 ints: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
------------------------------------------------------------------------------------------------
Join w 2 ints wholestage off 138514 / 139178 0.2 6604.9 1.0X
Join w 2 ints wholestage on 129908 / 140869 0.2 6194.5 1.1X
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ur, is this correct? Previously, we had the followings.

     *Join w 2 ints codegen=false              4426 / 4501          4.7         211.1       1.0X
     *Join w 2 ints codegen=true                791 /  818         26.5          37.7       5.6X

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's correct, I ran it on master:

build/sbt "sql/test-only *benchmark.JoinBenchmark"
......
[info] JoinBenchmark:
[info] - broadcast hash join, long key !!! IGNORED !!!
[info] - broadcast hash join, long key with duplicates !!! IGNORED !!!
Running benchmark: Join w 2 ints
  Running case: Join w 2 ints wholestage off
  Stopped after 2 iterations, 307335 ms
  Running case: Join w 2 ints wholestage on
  Stopped after 5 iterations, 687107 ms

Java HotSpot(TM) 64-Bit Server VM 1.8.0_151-b12 on Mac OS X 10.12.6
Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz

Join w 2 ints:                           Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
------------------------------------------------------------------------------------------------
Join w 2 ints wholestage off              153532 / 153668          0.1        7321.0       1.0X
Join w 2 ints wholestage on               132075 / 137422          0.2        6297.8       1.2X

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting. Although it's beyond the scope, could you run on branch-2.4 and branch-2.3 please, too?

def broadcastHashJoinLongKeyWithDuplicates(): Unit = {
val N = 20 << 20
val M = 1 << 16

val dim = broadcast(spark.range(M).selectExpr("cast(id/10 as long) as k"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this change, we need rerun the benchmark to get a new result.

@SparkQA
Copy link

SparkQA commented Oct 11, 2018

Test build #97243 has finished for PR 22661 at commit 2baaf35.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 11, 2018

Test build #97249 has finished for PR 22661 at commit 00c4950.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -19,229 +19,161 @@ package org.apache.spark.sql.execution.benchmark

import org.apache.spark.sql.execution.joins._
import org.apache.spark.sql.functions._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.IntegerType

/**
* Benchmark to measure performance for aggregate primitives.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aggregate primitives -> joins

*shuffle hash join codegen=false 2005 / 2010 2.1 478.0 1.0X
*shuffle hash join codegen=true 1773 / 1792 2.4 422.7 1.1X
*/
override def runBenchmarkSuite(): Unit = {
Copy link
Member

@dongjoon-hyun dongjoon-hyun Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap the followings(line 168~177) with something like runBenchmark("Join Benchmark")?

@SparkQA
Copy link

SparkQA commented Oct 11, 2018

Test build #97279 has finished for PR 22661 at commit 3be13b1.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum
Copy link
Member Author

wangyum commented Oct 11, 2018

retest this please

@SparkQA
Copy link

SparkQA commented Oct 12, 2018

Test build #97287 has finished for PR 22661 at commit 3be13b1.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

runBenchmark("merge join", N) {
val df1 = sparkSession.range(N).selectExpr(s"id * 2 as k1")
val df2 = sparkSession.range(N).selectExpr(s"id * 3 as k2")
codegenBenchmark("merge join", N) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge join -> sort merge join

@dongjoon-hyun
Copy link
Member

@wangyum . Could you review and merge wangyum#18 ?

*-------------------------------------------------------------------------------------------
*Join w 2 ints codegen=false 4426 / 4501 4.7 211.1 1.0X
*Join w 2 ints codegen=true 791 / 818 26.5 37.7 5.6X
*/
Copy link
Member

@dongjoon-hyun dongjoon-hyun Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @cloud-fan , @gatorsmile , @davies , @rxin .

We are hitting some performance slowdown in benchmark. However, this is not a regression because it's consistent in 2.0.2 ~ 2.4.0-rc3.

Join w 2 ints:                           Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
------------------------------------------------------------------------------------------------
Join w 2 ints wholestage off              157742 / 158892          0.1        7521.7       1.0X
Join w 2 ints wholestage on               134290 / 152917          0.2        6403.4       1.2X

According to the original performance number, it seems to be a result when HashJoin.rewriteKeyExpr uses a simple upcasting to bigint. However, the current code generates a result where HashJoin.rewriteKeyExpr uses shiftleft operations.

scala> val df = spark.range(N).join(dim2, (col("id") % M).cast(IntegerType) === col("k1") && (col("id") % M).cast(IntegerType) === col("k2"))

scala> val df2 = spark.range(N).join(dim2, (col("id") % M) === col("k1") && (col("id") % M) === col("k2"))

scala> df.explain
== Physical Plan ==
*(2) BroadcastHashJoin [cast((id#8L % 65536) as int), cast((id#8L % 65536) as int)], [k1#2, k2#3], Inner, BuildRight
:- *(2) Range (0, 20971520, step=1, splits=8)
+- BroadcastExchange HashedRelationBroadcastMode(List((shiftleft(cast(input[0, int, false] as bigint), 32) | (cast(input[1, int, false] as bigint) & 4294967295))))
   +- *(1) Project [cast(id#0L as int) AS k1#2, cast(id#0L as int) AS k2#3, cast(id#0L as string) AS v#4]
      +- *(1) Range (0, 65536, step=1, splits=8)

scala> df2.explain
== Physical Plan ==
*(2) BroadcastHashJoin [(id#23L % 65536), (id#23L % 65536)], [cast(k1#2 as bigint), cast(k2#3 as bigint)], Inner, BuildRight
:- *(2) Range (0, 20971520, step=1, splits=8)
+- BroadcastExchange HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint), cast(input[1, int, false] as bigint)))
   +- *(1) Project [cast(id#0L as int) AS k1#2, cast(id#0L as int) AS k2#3, cast(id#0L as string) AS v#4]
      +- *(1) Range (0, 65536, step=1, splits=8)

Did we really want to measure the difference in HashJoin.rewriteKeyExpr?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any advice is welcome and thank you in advance, @cloud-fan , @gatorsmile , @davies , @rxin .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems caused by the bug fix: #15390

So the performance is reasonable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for confirmation, @cloud-fan !

@@ -200,11 +200,12 @@ private[spark] object Benchmark {
def getProcessorName(): String = {
val cpu = if (SystemUtils.IS_OS_MAC_OSX) {
Utils.executeAndGetOutput(Seq("/usr/sbin/sysctl", "-n", "machdep.cpu.brand_string"))
.stripLineEnd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the Mac has one more line than Linux:
28f9b9a#diff-45c96c65f7c46bc2d84843a7cb92f22fL7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ur.. I'm not a fan to piggy-backing. Okay.

@SparkQA
Copy link

SparkQA commented Oct 12, 2018

Test build #97299 has finished for PR 22661 at commit 28f9b9a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Join w 2 ints: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative
------------------------------------------------------------------------------------------------
Join w 2 ints wholestage off 173174 / 173183 0.1 8257.6 1.0X
Join w 2 ints wholestage on 166350 / 198362 0.1 7932.2 1.0X
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this surprises me that whole stage codegen doesn't help. We should investigate it later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.

@SparkQA
Copy link

SparkQA commented Oct 12, 2018

Test build #97301 has finished for PR 22661 at commit cd8b664.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Thank you, @wangyum and @cloud-fan .

Merged to master.

@asfgit asfgit closed this in e965fb5 Oct 12, 2018
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
## What changes were proposed in this pull request?

Refactor `JoinBenchmark` to use main method.
1. use `spark-submit`:
```console
bin/spark-submit --class  org.apache.spark.sql.execution.benchmark.JoinBenchmark --jars ./core/target/spark-core_2.11-3.0.0-SNAPSHOT-tests.jar ./sql/catalyst/target/spark-sql_2.11-3.0.0-SNAPSHOT-tests.jar
```

2. Generate benchmark result:
```console
SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain org.apache.spark.sql.execution.benchmark.JoinBenchmark"
```

## How was this patch tested?

manual tests

Closes apache#22661 from wangyum/SPARK-25664.

Lead-authored-by: Yuming Wang <yumwang@ebay.com>
Co-authored-by: Yuming Wang <wgyumg@gmail.com>
Co-authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants