forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-27189][CORE] Add Executor metrics and memory usage instrumenta…
…tion to the metrics system ## What changes were proposed in this pull request? This PR proposes to add instrumentation of memory usage via the Spark Dropwizard/Codahale metrics system. Memory usage metrics are available via the Executor metrics, recently implemented as detailed in https://issues.apache.org/jira/browse/SPARK-23206. Additional notes: This takes advantage of the metrics poller introduced in apache#23767. ## Why are the changes needed? Executor metrics bring have many useful insights on memory usage, in particular on the usage of storage memory and executor memory. This is useful for troubleshooting. Having the information in the metrics systems allows to add those metrics to Spark performance dashboards and study memory usage as a function of time, as in the example graph https://issues.apache.org/jira/secure/attachment/12962810/Example_dashboard_Spark_Memory_Metrics.PNG ## Does this PR introduce any user-facing change? Adds `ExecutorMetrics` source to publish executor metrics via the Dropwizard metrics system. Details of the available metrics in docs/monitoring.md Adds configuration parameter `spark.metrics.executormetrics.source.enabled` ## How was this patch tested? Tested on YARN cluster and with an existing setup for a Spark dashboard based on InfluxDB and Grafana. Closes apache#24132 from LucaCanali/memoryMetricsSource. Authored-by: Luca Canali <[email protected]> Signed-off-by: Imran Rashid <[email protected]>
- Loading branch information
1 parent
a717d21
commit 729f43f
Showing
7 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
65 changes: 65 additions & 0 deletions
65
core/src/main/scala/org/apache/spark/executor/ExecutorMetricsSource.scala
This file contains 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,65 @@ | ||
/* | ||
* 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 com.codahale.metrics.{Gauge, MetricRegistry} | ||
|
||
import org.apache.spark.metrics.{ExecutorMetricType, MetricsSystem} | ||
import org.apache.spark.metrics.source.Source | ||
|
||
/** | ||
* Expose executor metrics from [[ExecutorMetricsType]] using the Dropwizard metrics system. | ||
* | ||
* Metrics related to the memory system can be expensive to gather, therefore | ||
* we implement some optimizations: | ||
* (1) Metrics values are cached, updated at each heartbeat (default period is 10 seconds). | ||
* An alternative faster polling mechanism is used, only if activated, by setting | ||
* spark.executor.metrics.pollingInterval=<interval in ms>. | ||
* (2) Procfs metrics are gathered all in one-go and only conditionally: | ||
* if the /proc filesystem exists | ||
* and spark.eventLog.logStageExecutorProcessTreeMetrics.enabled=true | ||
* and spark.eventLog.logStageExecutorMetrics.enabled=true. | ||
*/ | ||
private[spark] class ExecutorMetricsSource extends Source { | ||
|
||
override val metricRegistry = new MetricRegistry() | ||
override val sourceName = "ExecutorMetrics" | ||
@volatile var metricsSnapshot: Array[Long] = Array.fill(ExecutorMetricType.numMetrics)(0L) | ||
|
||
// called by ExecutorMetricsPoller | ||
def updateMetricsSnapshot(metricsUpdates: Array[Long]): Unit = { | ||
metricsSnapshot = metricsUpdates | ||
} | ||
|
||
private class ExecutorMetricGauge(idx: Int) extends Gauge[Long] { | ||
def getValue: Long = metricsSnapshot(idx) | ||
} | ||
|
||
def register(metricsSystem: MetricsSystem): Unit = { | ||
val gauges: IndexedSeq[ExecutorMetricGauge] = (0 until ExecutorMetricType.numMetrics).map { | ||
idx => new ExecutorMetricGauge(idx) | ||
}.toIndexedSeq | ||
|
||
ExecutorMetricType.metricToOffset.foreach { | ||
case (name, idx) => | ||
metricRegistry.register(MetricRegistry.name(name), gauges(idx)) | ||
} | ||
|
||
metricsSystem.registerSource(this) | ||
} | ||
} |
This file contains 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 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 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