You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ForVic (via GitHub)" <gi...@apache.org> on 2025/08/06 19:07:54 UTC
[PR] [IN PROGRESS] Log metrics for the driver when the application ends [spark]
ForVic opened a new pull request, #51882:
URL: https://github.com/apache/spark/pull/51882
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
Report a heartbeat on the driver when the application stops.
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
Some spark applications do not launch any jobs or stages, and are used as 'driver-only' jobs. Spark tracks memory metrics at a per-stage level, including for the driver. This isn't a strict requirement for the driver, and is done as a way to simplify the internal state of metric collection, so a driver container can be treated the same as an executor one. However, this results in some applications not having driver memory metrics at all, e.g. in SHS as writing memory metrics to the event log is only done on stage completion. Although driver memory was being used and tracked, it is never logged.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Tested with a custom job that was driver-only, previously this would have no metrics in SHS, now we see:
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm closed pull request #51882: [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends
URL: https://github.com/apache/spark/pull/51882
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on code in PR #51882:
URL: https://github.com/apache/spark/pull/51882#discussion_r2296787039
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2934,8 +2934,15 @@ class SparkContext(config: SparkConf) extends Logging {
_driverLogger.foreach(_.startSync(_hadoopConfiguration))
}
- /** Post the application end event */
+ /** Post the application end event and report the final heartbeat */
private def postApplicationEnd(exitCode: Int): Unit = {
+ try {
+ _heartbeater.doReportHeartbeat()
+ } catch {
+ case t: Throwable =>
+ logError("Error while reporting heartbeat metrics for the driver " +
+ "during application shutdown.", t);
Review Comment:
```suggestion
logInfo("Unable to report driver heartbeat metrics when stopping spark context.", t);
```
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2934,8 +2934,15 @@ class SparkContext(config: SparkConf) extends Logging {
_driverLogger.foreach(_.startSync(_hadoopConfiguration))
}
- /** Post the application end event */
+ /** Post the application end event and report the final heartbeat */
private def postApplicationEnd(exitCode: Int): Unit = {
+ try {
+ _heartbeater.doReportHeartbeat()
+ } catch {
+ case t: Throwable =>
+ logError("Error while reporting heartbeat metrics for the driver " +
+ "during application shutdown.", t);
Review Comment:
```suggestion
logInfo("Unable to report driver heartbeat metrics when stopping spark context", t);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "ForVic (via GitHub)" <gi...@apache.org>.
ForVic commented on code in PR #51882:
URL: https://github.com/apache/spark/pull/51882#discussion_r2298889743
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2934,8 +2934,15 @@ class SparkContext(config: SparkConf) extends Logging {
_driverLogger.foreach(_.startSync(_hadoopConfiguration))
}
- /** Post the application end event */
+ /** Post the application end event and report the final heartbeat */
private def postApplicationEnd(exitCode: Int): Unit = {
+ try {
+ _heartbeater.doReportHeartbeat()
Review Comment:
Yes, the goal here is best effort, given we are already in a 'failure' scenario it may not always succeed, but when it does, we get a better signal. We already report memory statistics on every `EXECUTOR_HEARTBEAT_INTERVAL` seconds https://github.com/apache/spark/blob/bc36a7db43f287af536bb2767d7d9f1d70bc799f/core/src/main/scala/org/apache/spark/SparkContext.scala#L617
regardless of memory pressure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "ForVic (via GitHub)" <gi...@apache.org>.
ForVic commented on PR #51882:
URL: https://github.com/apache/spark/pull/51882#issuecomment-3161719095
cc @mridulm @robreeves @shardulm94
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #51882:
URL: https://github.com/apache/spark/pull/51882#issuecomment-3226724337
The proposed change itself looks good to me.
Can you update to latest @ForVic ? To see if that helps us get a clean build.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "itskals (via GitHub)" <gi...@apache.org>.
itskals commented on code in PR #51882:
URL: https://github.com/apache/spark/pull/51882#discussion_r2295022069
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2934,8 +2934,15 @@ class SparkContext(config: SparkConf) extends Logging {
_driverLogger.foreach(_.startSync(_hadoopConfiguration))
}
- /** Post the application end event */
+ /** Post the application end event and report the final heartbeat */
private def postApplicationEnd(exitCode: Int): Unit = {
+ try {
+ _heartbeater.doReportHeartbeat()
Review Comment:
When facing memory issues, this call might also reach this point. Do you know if we are targeting the best effort scenario? Seems like the best effort attempt.
On a side note, what is your opinion on the reporter starting to report memory pressure at around 80%, which can help metrics consumers improve reliability and achieve better correlation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "ForVic (via GitHub)" <gi...@apache.org>.
ForVic commented on PR #51882:
URL: https://github.com/apache/spark/pull/51882#issuecomment-3246555029
Thanks for the reviews @itskals and @mridulm !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "itskals (via GitHub)" <gi...@apache.org>.
itskals commented on code in PR #51882:
URL: https://github.com/apache/spark/pull/51882#discussion_r2295022069
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2934,8 +2934,15 @@ class SparkContext(config: SparkConf) extends Logging {
_driverLogger.foreach(_.startSync(_hadoopConfiguration))
}
- /** Post the application end event */
+ /** Post the application end event and report the final heartbeat */
private def postApplicationEnd(exitCode: Int): Unit = {
+ try {
+ _heartbeater.doReportHeartbeat()
Review Comment:
When experiencing memory issues, this code might not even make it to this point. Are we aiming for the best effort scenario? That seems to be the case to me.
On a side note, what is your opinion on the reporter starting to report memory pressure at around 80%, which can help metrics consumers improve reliability and achieve better correlation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "itskals (via GitHub)" <gi...@apache.org>.
itskals commented on code in PR #51882:
URL: https://github.com/apache/spark/pull/51882#discussion_r2295022069
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2934,8 +2934,15 @@ class SparkContext(config: SparkConf) extends Logging {
_driverLogger.foreach(_.startSync(_hadoopConfiguration))
}
- /** Post the application end event */
+ /** Post the application end event and report the final heartbeat */
private def postApplicationEnd(exitCode: Int): Unit = {
+ try {
+ _heartbeater.doReportHeartbeat()
Review Comment:
When facing memory issues, this code might not also reach this point. Are we targeting the best effort scenario? Seems so to me.
On a side note, what is your opinion on the reporter starting to report memory pressure at around 80%, which can help metrics consumers improve reliability and achieve better correlation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #51882:
URL: https://github.com/apache/spark/pull/51882#issuecomment-3240858281
Merged to master.
Thanks for adding this @ForVic !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53156][CORE] Track Driver Memory Metrics when the Application ends [spark]
Posted by "ForVic (via GitHub)" <gi...@apache.org>.
ForVic commented on PR #51882:
URL: https://github.com/apache/spark/pull/51882#issuecomment-3189838931
Test failure looks unrelated - `SparkConnectServiceSuite:SPARK-44776: LocalTableScanExec`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org