-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-23429][CORE] Add executor memory metrics to heartbeat and expose in executors REST API #21221
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
Closed
Closed
[SPARK-23429][CORE] Add executor memory metrics to heartbeat and expose in executors REST API #21221
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c8e8abe
SPARK-23429: Add executor memory metrics to heartbeat and expose in e…
edwinalu 5d6ae1c
modify MimaExcludes.scala to filter changes to SparkListenerExecutorM…
edwinalu ad10d28
Address code review comments, change event logging to stage end.
edwinalu 10ed328
Add configuration parameter spark.eventLog.logExecutorMetricsUpdates.…
edwinalu 2d20367
wip on enum based metrics
squito f904f1e
wip ... has both enum and non-enum version
squito c502ec4
case objects, mostly complete
squito 7879e66
Merge pull request #1 from squito/metric_enums
edwinalu 2662f6f
Address comments (move heartbeater from DAGScheduler to SparkContext,…
edwinalu 2871335
SPARK-23429: Add executor memory metrics to heartbeat and expose in e…
edwinalu da83f2e
modify MimaExcludes.scala to filter changes to SparkListenerExecutorM…
edwinalu f25a44b
Address code review comments, change event logging to stage end.
edwinalu ca85c82
Add configuration parameter spark.eventLog.logExecutorMetricsUpdates.…
edwinalu 8b74ba8
wip on enum based metrics
squito 036148c
wip ... has both enum and non-enum version
squito 91fb1db
case objects, mostly complete
squito 2d8894a
Address comments (move heartbeater from DAGScheduler to SparkContext,…
edwinalu 99044e6
Merge branch 'SPARK-23429.2' of https://github.com/edwinalu/spark int…
edwinalu 263c8c8
code review comments
edwinalu 812fdcf
code review comments:
edwinalu 7ed42a5
Address code review comments. Also make executorUpdates in SparkListe…
edwinalu 8d9acdf
Revert and make executorUpdates in SparkListenerExecutorMetricsUpdate…
edwinalu 20799d2
code review comments: hid array implementation of executor metrics, a…
edwinalu 8905d23
merge with master
edwinalu a0eed11
address code review comments
edwinalu 03cd5bc
code review comments
edwinalu 10e7f15
Merge branch 'master' into SPARK-23429.2
edwinalu a14b82a
merge conflicts
edwinalu 2897281
disable stage executor metrics logging by default
edwinalu ee4aa1d
Merge branch 'master' into SPARK-23429.2
edwinalu 571285b
fix indentation
edwinalu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import org.apache.spark.executor.ExecutorMetrics | ||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.memory.MemoryManager | ||
import org.apache.spark.metrics.ExecutorMetricType | ||
import org.apache.spark.util.{ThreadUtils, Utils} | ||
|
||
/** | ||
* Creates a heartbeat thread which will call the specified reportHeartbeat function at | ||
* intervals of intervalMs. | ||
* | ||
* @param memoryManager the memory manager for execution and storage memory. | ||
* @param reportHeartbeat the heartbeat reporting function to call. | ||
* @param name the thread name for the heartbeater. | ||
* @param intervalMs the interval between heartbeats. | ||
*/ | ||
private[spark] class Heartbeater( | ||
memoryManager: MemoryManager, | ||
reportHeartbeat: () => Unit, | ||
name: String, | ||
intervalMs: Long) extends Logging { | ||
// Executor for the heartbeat task | ||
private val heartbeater = ThreadUtils.newDaemonSingleThreadScheduledExecutor(name) | ||
|
||
/** Schedules a task to report a heartbeat. */ | ||
def start(): Unit = { | ||
// Wait a random interval so the heartbeats don't end up in sync | ||
val initialDelay = intervalMs + (math.random * intervalMs).asInstanceOf[Int] | ||
|
||
val heartbeatTask = new Runnable() { | ||
override def run(): Unit = Utils.logUncaughtExceptions(reportHeartbeat()) | ||
} | ||
heartbeater.scheduleAtFixedRate(heartbeatTask, initialDelay, intervalMs, TimeUnit.MILLISECONDS) | ||
} | ||
|
||
/** Stops the heartbeat thread. */ | ||
def stop(): Unit = { | ||
heartbeater.shutdown() | ||
heartbeater.awaitTermination(10, TimeUnit.SECONDS) | ||
} | ||
|
||
/** | ||
* Get the current executor level metrics. These are returned as an array, with the index | ||
* determined by MetricGetter.values | ||
*/ | ||
def getCurrentMetrics(): ExecutorMetrics = { | ||
val metrics = ExecutorMetricType.values.map(_.getMetricValue(memoryManager)).toArray | ||
new ExecutorMetrics(metrics) | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
core/src/main/scala/org/apache/spark/executor/ExecutorMetrics.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.executor | ||
|
||
import org.apache.spark.annotation.DeveloperApi | ||
import org.apache.spark.metrics.ExecutorMetricType | ||
|
||
/** | ||
* :: DeveloperApi :: | ||
* Metrics tracked for executors and the driver. | ||
* | ||
* Executor-level metrics are sent from each executor to the driver as part of the Heartbeat. | ||
*/ | ||
@DeveloperApi | ||
class ExecutorMetrics private[spark] extends Serializable { | ||
|
||
// Metrics are indexed by MetricGetter.values | ||
private val metrics = new Array[Long](ExecutorMetricType.values.length) | ||
|
||
// the first element is initialized to -1, indicating that the values for the array | ||
// haven't been set yet. | ||
metrics(0) = -1 | ||
|
||
/** Returns the value for the specified metricType. */ | ||
def getMetricValue(metricType: ExecutorMetricType): Long = { | ||
metrics(ExecutorMetricType.metricIdxMap(metricType)) | ||
} | ||
|
||
/** Returns true if the values for the metrics have been set, false otherwise. */ | ||
def isSet(): Boolean = metrics(0) > -1 | ||
|
||
private[spark] def this(metrics: Array[Long]) { | ||
this() | ||
Array.copy(metrics, 0, this.metrics, 0, Math.min(metrics.size, this.metrics.size)) | ||
} | ||
|
||
/** | ||
* Constructor: create the ExecutorMetrics with the values specified. | ||
* | ||
* @param executorMetrics map of executor metric name to value | ||
*/ | ||
private[spark] def this(executorMetrics: Map[String, Long]) { | ||
this() | ||
(0 until ExecutorMetricType.values.length).foreach { idx => | ||
metrics(idx) = executorMetrics.getOrElse(ExecutorMetricType.values(idx).name, 0L) | ||
} | ||
} | ||
|
||
/** | ||
* Compare the specified executor metrics values with the current executor metric values, | ||
* and update the value for any metrics where the new value for the metric is larger. | ||
* | ||
* @param executorMetrics the executor metrics to compare | ||
* @return if there is a new peak value for any metric | ||
*/ | ||
private[spark] def compareAndUpdatePeakValues(executorMetrics: ExecutorMetrics): Boolean = { | ||
var updated = false | ||
|
||
(0 until ExecutorMetricType.values.length).foreach { idx => | ||
if (executorMetrics.metrics(idx) > metrics(idx)) { | ||
updated = true | ||
metrics(idx) = executorMetrics.metrics(idx) | ||
} | ||
} | ||
updated | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Out of curiosity, why are we using an array here with index-based fetching? We could use a struct / case class to represent these metrics. But I suppose the size of the payload we send is smaller if we use an Array, and we don't want to pay serialization costs?
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 suggested this earlier in the reviews. Most of the operations for dealing with this data want to iterate over all the fields. its much easier this way vs. having a bazillion
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.
Yup that's fine - I did some googling, unfortunately there isn't a great way to iterate over fields of a case class. You could create a thin wrapper object around the array instead though, if we really think the nicer API is worthwhile:
Or even this:
The latter which would be better because you'd be guaranteed to create the struct with the right number of metrics. Though such abstractions are not necessary by any means.
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.
Is it likely that users would want to access the individual fields, rather than iterating through all? The 1st option would be a bit nicer if so.
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.
Unclear - if we expose these metrics to some external consumer via an API for example, then we almost certainly want to have a schema labelling these fields for consumption by e.g. dashboards. I think what we have here is fine for now.