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-12950] [SQL] Improve lookup of BytesToBytesMap in aggregate #11010

Closed
wants to merge 12 commits into from

Conversation

davies
Copy link
Contributor

@davies davies commented Feb 2, 2016

This PR improve the lookup of BytesToBytesMap by:

  1. Generate code for calculate the hash code of grouping keys.
  2. Do not use MemoryLocation, fetch the baseObject and offset for key and value directly (remove the indirection).

Without codegen 7775.53 26.97 1.00 X
With codegen 342.15 612.94 22.73 X
Without codegen 5488.16 38.21 1.00 X
With codegen 531.08 394.88 10.33 X
Copy link
Contributor

Choose a reason for hiding this comment

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

what's causing the big drop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The benchmark is not that stable, this number change from 10 to 20, maybe 200M are still not enough, I will increase it to 500M.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want to increase it by 10x to amortize the fixed overhead. The runtime was 342 ms, which is too small.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we will wait more than 2 minutes to finish this benchmark, I will send another PR to update these benchmark.

@SparkQA
Copy link

SparkQA commented Feb 2, 2016

Test build #2487 has finished for PR 11010 at commit 4cefbc5.

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

* A function that calculates hash value for a group of expressions, which basically XOR all the
* hash code of children expressions together.
*
* Note: This is used for hash map for aggreagte, designed for performance (has worse
Copy link
Contributor

Choose a reason for hiding this comment

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

Does UnsafeRow.hashCode slower than this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UnsafeRow will call murmur3, which is still slow

Davies Liu added 3 commits February 3, 2016 09:46
Conflicts:
	sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala
	sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/TungstenAggregate.scala
	sql/core/src/test/scala/org/apache/spark/sql/execution/BenchmarkWholeStageCodegen.scala
Conflicts:
	sql/core/src/test/scala/org/apache/spark/sql/execution/BenchmarkWholeStageCodegen.scala
@SparkQA
Copy link

SparkQA commented Feb 3, 2016

Test build #50705 has finished for PR 11010 at commit 5eff34b.

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

Davies Liu added 4 commits February 3, 2016 17:25
Conflicts:
	sql/core/src/test/scala/org/apache/spark/sql/execution/BenchmarkWholeStageCodegen.scala
@SparkQA
Copy link

SparkQA commented Feb 4, 2016

Test build #50723 has finished for PR 11010 at commit 53a2dd4.

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

@SparkQA
Copy link

SparkQA commented Feb 4, 2016

Test build #50734 has finished for PR 11010 at commit 6c9ce88.

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

@SparkQA
Copy link

SparkQA commented Feb 4, 2016

Test build #50736 has finished for PR 11010 at commit 85f8d0e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • public class TaskMemoryManager

@nongli
Copy link
Contributor

nongli commented Feb 4, 2016

Do you know how much of this is from the general clean up and how much is from switching to a simpler hash? In my experience, using a very weak hash function can make things really bad if you dont account for it other ways.

@davies
Copy link
Contributor Author

davies commented Feb 5, 2016

@nongli As the benchmark show, the weak hash function could save 10ns per row, others may save 20ns per row. I'm also not sure the weak hash function is enough in this cases. BTW, the hashCode of ing/long in Java are also using this weak hash function, so they may not that bad.

@davies
Copy link
Contributor Author

davies commented Feb 9, 2016

@nongli Had reverted it to Murmur3 (we could figure out a faster hash function later), the improvements become minor.

@nongli
Copy link
Contributor

nongli commented Feb 10, 2016

LGTM

@SparkQA
Copy link

SparkQA commented Feb 10, 2016

Test build #50999 has finished for PR 11010 at commit 7f5852a.

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

@davies
Copy link
Contributor Author

davies commented Feb 10, 2016

Merging this into master, thanks!

@asfgit asfgit closed this in 0e5ebac Feb 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants