Skip to content

Conversation

@cloud-fan
Copy link
Contributor

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

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've also tried the commit before this PR, the benchmark result is almost same.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

several learnings:

  1. limit does help
  2. The performance is bad if we interrupt the data processing loop too often. Full scan is the worst case, we interrupt the loop for every record.

@cloud-fan
Copy link
Contributor Author

cc @kiszk @viirya @mgaido91

| $stopCheck
| }
| $nextIndex = $batchEnd;
| $numOutput.add($localEnd);
Copy link
Contributor

Choose a reason for hiding this comment

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

this means now the metrics are updated only once the whole processing of a batch happens 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.

partially yes, when there is no stop check.

If there is stop check, we will directly return and won't hit this code path.

Copy link
Contributor

Choose a reason for hiding this comment

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

also in that case we update the metrics after processing the rows, right?

i am just wondering if we can think of updating the metrics as before but in the shouldStop() "remove" the rows which were not processed. This would let the metrics to be updated earlier as before, but it can also cause the metrics to decrease which is something not expected. Not sure which is worse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we can think of updating the metrics as before but in the shouldStop() "remove" the rows which were not processed.

Is it to keep the code diff small? Otherwise I think it's always better to only update metrics once, instead of add-then-remove.

| $stopCheck
| }
| $nextIndex = $batchEnd;
| $numOutput.add($localEnd);
Copy link
Member

Choose a reason for hiding this comment

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

I image a case. There is range + limit + a blocking op + ...

Now as at the range there is no stopCheck, right?

Assume a range batch is 1000. Because there is no stopCheck, this loop on localIdx will run to end. Although the limit works to only pass n rows into the blocking op, here we still add localEnd into numOutput.

I've not really tested it. Not sure if it is really a problem. Since it is late, I may check it more tomorrow if it has not figured out yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's expected isn't it? The range operator does output 1000 rows, the limit operator takes 1000 inputs, but only output like 100 rows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

more background: the stop check for limit is done in batch granularity, while the stop check for result buffer is done in row granularity.

That said, even if the limit is smaller than the batch size, the range operator still outputs a entire batch, physically.

Copy link
Member

Choose a reason for hiding this comment

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

If it is, then it is no problem. I was thinking that the number of output metric at range operator should be 100 if it is followed by a limit(100) operator.

@SparkQA
Copy link

SparkQA commented Oct 11, 2018

Test build #97264 has finished for PR 22698 at commit 1071c14.

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

* Benchmark to measure performance for range operator.
* To run this benchmark:
* {{{
* 1. without sbt: bin/spark-submit --class <this class> <spark sql test jar>
Copy link
Member

Choose a reason for hiding this comment

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

1. without sbt: bin/spark-submit --class <this class> <spark sql test jar>

->

1. without sbt:
    bin/spark-submit --class <this class> --jars <spark core test jar> <spark sql test jar>

@SparkQA
Copy link

SparkQA commented Oct 12, 2018

Test build #97293 has finished for PR 22698 at commit 4058a21.

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

@mgaido91
Copy link
Contributor

LGTM

2 similar comments
@viirya
Copy link
Member

viirya commented Oct 12, 2018

LGTM

@kiszk
Copy link
Member

kiszk commented Oct 12, 2018

LGTM

@cloud-fan
Copy link
Contributor Author

thanks, merging to master!

@asfgit asfgit closed this in 34f229b Oct 13, 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?

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]>
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