-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31315][SQL] SQLQueryTestSuite: Display the total compile time for generated java code #28081
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
Conversation
|
Test build #120643 has finished for PR 28081 at commit
|
| val codegenInfo = | ||
| s""" | ||
| |=== Metrics of Whole Codegen === | ||
| |Total compile time: ${CodeGenerator.compileTime.sum.toDouble / NANOS_PER_SECOND} seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, we need to reset this metric in beforeAll? btw , could we reuse CodegenMetrics.METRIC_COMPILATION_TIME for this purpose? Getting the same metric for the same purpose seems redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I wanted to use CodegenMetrics.METRIC_COMPILATION_TIME to do this. After many experiments, I found that CodegenMetrics.METRIC_COMPILATION_TIME is only effective for a single test case, and cannot play a role in the whole life cycle of SQLQueryTestSuite.
I checked the type of CodegenMetrics.METRIC_COMPILATION_TIME is Histogram that is it only preserves 1028 elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maropu Histogram is a metric which calculates the distribution of a value.
|
Could we display this metric in |
|
Test build #120662 has finished for PR 28081 at commit
|
| val duration = endTime - startTime | ||
| val timeMs: Double = duration.toDouble / NANOS_PER_MILLIS | ||
| CodegenMetrics.METRIC_SOURCE_CODE_SIZE.update(code.body.length) | ||
| CodegenMetrics.METRIC_COMPILATION_TIME.update(timeMs.toLong) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodegenMetrics.METRIC_COMPILATION_TIME is a Histogram that is a metric which calculates the distribution of a value. We can't reuse it.
| CodegenMetrics.METRIC_SOURCE_CODE_SIZE.update(code.body.length) | ||
| CodegenMetrics.METRIC_COMPILATION_TIME.update(timeMs.toLong) | ||
| logInfo(s"Code generated in $timeMs ms") | ||
| _compileTime.add(duration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think timeMs is good enough to be recorded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeMs lost a lot of precision. Because SQLQueryTestSuite contains 231 test cases contain a lot of SQL, tens of thousands of SQL are executed. The loss of accuracy will increase.
...atalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
Show resolved
Hide resolved
dongjoon-hyun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a source code under src/main is changed, [TESTS] should not be used.
...atalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
Show resolved
Hide resolved
|
|
||
| def compileTime: Long = _compileTime.sum | ||
|
|
||
| def resetCompileTime: Unit = _compileTime.reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
| // bytecode instruction | ||
| final val MUTABLESTATEARRAY_SIZE_LIMIT = 32768 | ||
|
|
||
| // Display the total compile time for generating java code in the output of the test case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is designed for a test case, this is a general accumulator in the context of CodeGenerator. Could you revise into a more proper description?
cc @gatorsmile
Also, this doesn't Display anything here. The warning log happens in afterAll in SQLQueryTestSuite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will supplement a more proper description.
OK. Thank you. I get it. |
The run time of |
|
Test build #120704 has finished for PR 28081 at commit
|
| private val _compileTime = new LongAccumulator | ||
|
|
||
| // Visible for testing | ||
| def compileTime: Long = _compileTime.sum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention that it's time in nanoseconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will add it.
|
The last commit just adds a line of comment. I'm merging it to master, thanks! |
|
@cloud-fan @maropu @dongjoon-hyun Thanks for all your help! |
|
Test build #120717 has finished for PR 28081 at commit
|
| // bytecode instruction | ||
| final val MUTABLESTATEARRAY_SIZE_LIMIT = 32768 | ||
|
|
||
| // The java source code generated by whole codegen is compiled on the Driver side and sent to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @beliefer ,
I'm really sorry to post edit suggestions after the PR is merged. I noticed this PR just now...
If we have a chance to make follow-up changes, could you please update java code to Java code, and whole codegen to whole-stage codegen?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Thanks for your remind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beliefer can you send a followup PR to address it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan @rednaxelafx I make a followup PR #28112.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one? #28112
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
… for generated java code ### What changes were proposed in this pull request? After my investigation, SQLQueryTestSuite spent a lot of time to generate java code. This PR is related to #28081. #28081 used to display compile time, but this PR used to display generate time. This PR will add the following to `SQLQueryTestSuite`'s output. ``` === Metrics of Whole Codegen === Total generate time: 82.640913862 seconds Total compile time: 98.649663572 seconds ``` ### Why are the changes needed? Display the total generate time for generated java code. ### Does this PR introduce any user-facing change? 'No'. ### How was this patch tested? Jenkins test. Closes #28105 from beliefer/output-codegen-generation-time. Lead-authored-by: beliefer <[email protected]> Co-authored-by: Jiaan Geng <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
…for generated java code ### What changes were proposed in this pull request? After my investigation, `SQLQueryTestSuite` spent a lot of time compiling the generated java code. Take `group-by.sql` as an example. At first, I added some debug log into `SQLQueryTestSuite`. Please reference https://github.com/beliefer/spark/blob/92b6af740c73e33007c21592023eb65635bb0f07/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala#L402 The execution command is as follows: `build/sbt "~sql/test-only *SQLQueryTestSuite -- -z group-by.sql"` The output show below: ``` 00:56:06.192 WARN org.apache.spark.sql.SQLQueryTestSuite: group-by.sql using configs: spark.sql.codegen.wholeStage=true. run time: 20604 00:56:13.719 WARN org.apache.spark.sql.SQLQueryTestSuite: group-by.sql using configs: spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=CODEGEN_ONLY. run time: 7526 00:56:18.786 WARN org.apache.spark.sql.SQLQueryTestSuite: group-by.sql using configs: spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=NO_CODEGEN. run time: 5066 ``` According to the log, we know. Config | Run time(ms) -- | -- spark.sql.codegen.wholeStage=true | 20604 spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=CODEGEN_ONLY | 7526 spark.sql.codegen.wholeStage=false,spark.sql.codegen.factoryMode=NO_CODEGEN | 5066 We should display the total compile time for generated java code. This PR will add the following to `SQLQueryTestSuite`'s output. ``` === Metrics of Whole Codegen === Total compile time: 80.564516529 seconds ``` Note: At first, I wanted to use `CodegenMetrics.METRIC_COMPILATION_TIME` to do this. After many experiments, I found that `CodegenMetrics.METRIC_COMPILATION_TIME` is only effective for a single test case, and cannot play a role in the whole life cycle of `SQLQueryTestSuite`. I checked the type of ` CodegenMetrics.METRIC_COMPILATION_TIME` is `Histogram` and the latter preserves 1028 elements.` Histogram` is a metric which calculates the distribution of a value. ### Why are the changes needed? Display the total compile time for generated java code. ### Does this PR introduce any user-facing change? 'No'. ### How was this patch tested? Jenkins test. Closes apache#28081 from beliefer/output-codegen-compile-time. Lead-authored-by: beliefer <[email protected]> Co-authored-by: gengjiaan <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
… for generated java code ### What changes were proposed in this pull request? After my investigation, SQLQueryTestSuite spent a lot of time to generate java code. This PR is related to apache#28081. apache#28081 used to display compile time, but this PR used to display generate time. This PR will add the following to `SQLQueryTestSuite`'s output. ``` === Metrics of Whole Codegen === Total generate time: 82.640913862 seconds Total compile time: 98.649663572 seconds ``` ### Why are the changes needed? Display the total generate time for generated java code. ### Does this PR introduce any user-facing change? 'No'. ### How was this patch tested? Jenkins test. Closes apache#28105 from beliefer/output-codegen-generation-time. Lead-authored-by: beliefer <[email protected]> Co-authored-by: Jiaan Geng <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
|
|
||
| // Reset compile time. | ||
| // Visible for testing | ||
| def resetCompileTime: Unit = _compileTime.reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods should be declared with parentheses, unless they are accessors that have no side-effect. See: https://github.com/databricks/scala-style-guide#parentheses
Fixed in #28252
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile Thanks. I got it now.
What changes were proposed in this pull request?
After my investigation,
SQLQueryTestSuitespent a lot of time compiling the generated java code.Take
group-by.sqlas an example.At first, I added some debug log into
SQLQueryTestSuite.Please reference https://github.com/beliefer/spark/blob/92b6af740c73e33007c21592023eb65635bb0f07/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala#L402
The execution command is as follows:
build/sbt "~sql/test-only *SQLQueryTestSuite -- -z group-by.sql"The output show below:
According to the log, we know.
We should display the total compile time for generated java code.
This PR will add the following to
SQLQueryTestSuite's output.Note: At first, I wanted to use
CodegenMetrics.METRIC_COMPILATION_TIMEto do this. After many experiments, I found thatCodegenMetrics.METRIC_COMPILATION_TIMEis only effective for a single test case, and cannot play a role in the whole life cycle ofSQLQueryTestSuite.I checked the type of
CodegenMetrics.METRIC_COMPILATION_TIMEisHistogramand the latter preserves 1028 elements.Histogramis a metric which calculates the distribution of a value.Why are the changes needed?
Display the total compile time for generated java code.
Does this PR introduce any user-facing change?
'No'.
How was this patch tested?
Jenkins test.