Skip to content

Conversation

@dbkerkela
Copy link
Contributor

Use LongAdder to make SQLMetrics thread safe.

What changes were proposed in this pull request?

Replace += with LongAdder.add() for concurrent counting

How was this patch tested?

Unit tests with local threads

Use LongAdder to make SQLMetrics threadsafe.
@hvanhovell
Copy link
Contributor

ok to test

@hvanhovell
Copy link
Contributor

add to whitelist


test("writing metrics from multiple threads") {
implicit val ec: ExecutionContextExecutor = ExecutionContext.global
val nThreads = 1000
Copy link
Contributor

Choose a reason for hiding this comment

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

nThreads? This is the number of futures right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True - I'll rename.

assert(acc.isZero())
}

test("writing metrics from multiple threads") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Really dumb question, does this fail without the fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Checking in a separate branch:
org.scalatest.exceptions.TestFailedException: 100000 did not equal 56544

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

FYI, I think this is not a valid test. Spark assumes there should be only one writer at the same time.

Copy link
Member

Choose a reason for hiding this comment

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

To be clear, we just need AccumulatorV2 can be read in the heart beat thread. That's the only place need to think about concurrence.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean it's a one-writer, multi-reader scene?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was originally raised because an implementation of broadcast join did have multiple writers. Unfortunately we recently determined that the LongAdder is causing a performance regression and we are going to revert this.
@cloud-fan or @hvanhovell can one of you send the rollback PR?

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean it's a one-writer, multi-reader scene?

Yes.

Copy link
Contributor

@hvanhovell hvanhovell left a comment

Choose a reason for hiding this comment

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

LGTM - pending jenkins

@SparkQA
Copy link

SparkQA commented Jun 25, 2018

Test build #92300 has finished for PR 21634 at commit deb08b9.

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

@SparkQA
Copy link

SparkQA commented Jun 25, 2018

Test build #92302 has finished for PR 21634 at commit 6a41d1b.

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

Copy link
Contributor

@HeartSaVioR HeartSaVioR left a comment

Choose a reason for hiding this comment

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

+1 Nice finding.

@hvanhovell
Copy link
Contributor

Merging to master. Thanks!

@asfgit asfgit closed this in 5264164 Jun 25, 2018
@cloud-fan
Copy link
Contributor

FYI I've reverted this patch w.r.t. #21634 (comment)

zzcclp added a commit to zzcclp/spark that referenced this pull request Dec 6, 2018
Use LongAdder to make SQLMetrics thread safe.

Replace += with LongAdder.add() for concurrent counting

Unit tests with local threads
zzcclp added a commit to zzcclp/spark that referenced this pull request Sep 20, 2019
Use LongAdder to make SQLMetrics thread safe.
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.

6 participants