-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20863] Add metrics/instrumentation to LiveListenerBus #18083
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
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a1fb5a8
WIP
JoshRosen a46c247
Fix test compilation
JoshRosen 378206e
Mock in EventLoggingListenerSuite
JoshRosen 37a1a7d
Address Wenchen's review comments.
JoshRosen 3b713a3
Add per-listener timing statistics.
JoshRosen 60c7448
Protect against registering thousands of listener classes.
JoshRosen dcecdae
Merge remote-tracking branch 'origin/master' into listener-bus-metrics
JoshRosen 4a083de
Minor cleanups.
JoshRosen d1a5e99
Add test for per-listener-class timer; rename method.
JoshRosen b8164b2
Merge remote-tracking branch 'origin/master' into listener-bus-metrics
JoshRosen f36fbaa
Use Option.
JoshRosen 76b669c
Add configuration.
JoshRosen 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
Protect against registering thousands of listener classes.
- Loading branch information
commit 60c7448d2cff7dd809f9d75ff48b31e21b88a915
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,13 @@ package org.apache.spark.scheduler | |
| import java.util.concurrent._ | ||
| import java.util.concurrent.atomic.{AtomicBoolean, AtomicLong} | ||
|
|
||
| import scala.collection.mutable | ||
| import scala.util.DynamicVariable | ||
|
|
||
| import com.codahale.metrics.{Counter, Gauge, MetricRegistry, Timer} | ||
| import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache} | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkContext} | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config._ | ||
| import org.apache.spark.metrics.MetricsSystem | ||
| import org.apache.spark.metrics.source.Source | ||
|
|
@@ -112,13 +113,8 @@ private[spark] class LiveListenerBus(conf: SparkConf) extends SparkListenerBus { | |
| } | ||
| } | ||
|
|
||
| override protected def createTimer(listener: SparkListenerInterface): Option[Timer] = { | ||
| if (listener.getClass.getName.startsWith("org.apache.spark")) { | ||
| metrics.perListenerTimers.size() | ||
| Some(metrics.perListenerTimers(listener.getClass.getSimpleName)) | ||
| } else { | ||
| None | ||
| } | ||
| override protected def getTimer(listener: SparkListenerInterface): Option[Timer] = { | ||
| metrics.getTimerForListener(listener) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -250,7 +246,8 @@ private[spark] object LiveListenerBus { | |
| val name = "SparkListenerBus" | ||
| } | ||
|
|
||
| private[spark] class LiveListenerBusMetrics(queue: LinkedBlockingQueue[_]) extends Source { | ||
| private[spark] | ||
| class LiveListenerBusMetrics(queue: LinkedBlockingQueue[_]) extends Source with Logging { | ||
| override val sourceName: String = "LiveListenerBus" | ||
| override val metricRegistry: MetricRegistry = new MetricRegistry | ||
|
|
||
|
|
@@ -281,15 +278,29 @@ private[spark] class LiveListenerBusMetrics(queue: LinkedBlockingQueue[_]) exten | |
| }) | ||
| } | ||
|
|
||
| // Guarded by synchronization. | ||
| private val perListenerClassTimers = mutable.Map[String, Timer]() | ||
|
|
||
| /** | ||
| * Mapping from fully-qualified listener class name to a timer tracking the processing time of | ||
| * events processed by that listener. | ||
| * Returns a timer tracking the processing time of the given listener class. | ||
| * events processed by that listener. This method is thread-safe. | ||
| */ | ||
| val perListenerTimers: LoadingCache[String, Timer] = | ||
| CacheBuilder.newBuilder().build[String, Timer](new CacheLoader[String, Timer] { | ||
| override def load(listenerName: String): Timer = { | ||
| metricRegistry.timer(MetricRegistry.name("listenerProcessingTime", listenerName)) | ||
| def getTimerForListener(listener: SparkListenerInterface): Option[Timer] = { | ||
| synchronized { | ||
| val className = listener.getClass.getName | ||
| val maxTimed = 128 | ||
|
||
| perListenerClassTimers.get(className).orElse { | ||
| if (perListenerClassTimers.size == maxTimed) { | ||
| logError(s"Not measuring processing time for listener class $className because a " + | ||
| s"maximum of $maxTimed listener classes are already timed.") | ||
| None | ||
| } else { | ||
| perListenerClassTimers(className) = | ||
| metricRegistry.timer(MetricRegistry.name("listenerProcessingTime", className)) | ||
| perListenerClassTimers.get(className) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
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.
is it possible that users register the same listener twice? Then the class name may not be a good identifier for listeners. I think this is the main problem of having listener-wise metrics, how to identify each listener?
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, but my goal with these metrics is to be able to identify which listeners are causing performance problems and for that purpose it's more useful to group listeners by class rather than to instrument individual listeners. Most (all?) of Spark's internal listeners have one instance per driver / SparkContext, so in practice keeping track of stats on a per-instance basis wouldn't actually be a meaningful difference in typical cases.
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'll update the PR description to discuss this per-listener metric.