-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-13988][Core] Make replaying event logs multi threaded in Histo…ry server to ensure a single large log does not block other logs from being rendered. #11800
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
7c3921c
[SPARK-13988][Core] Make replaying event logs multi threaded in Histo…
Parth-Brahmbhatt 704a619
Added a config to control number of processing threads for history se…
Parth-Brahmbhatt 858e8ff
Renaming the config to spark.history.fs.numReplayThreads.
Parth-Brahmbhatt 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,8 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) | |
|
|
||
| private val NOT_STARTED = "<Not Started>" | ||
|
|
||
| private val SPARK_HISTORY_FS_NUM_PROCESSING_THREADS = "spark.history.fs.num.processing.threads" | ||
|
|
||
| // Interval between safemode checks. | ||
| private val SAFEMODE_CHECK_INTERVAL_S = conf.getTimeAsSeconds( | ||
| "spark.history.fs.safemodeCheck.interval", "5s") | ||
|
|
@@ -89,6 +91,10 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) | |
| // Interval between each cleaner checks for event logs to delete | ||
| private val CLEAN_INTERVAL_S = conf.getTimeAsSeconds("spark.history.fs.cleaner.interval", "1d") | ||
|
|
||
| // Number of threads used to replay event logs. | ||
| private val NUM_PROCESSING_THREADS = conf.getInt(SPARK_HISTORY_FS_NUM_PROCESSING_THREADS, | ||
| Math.ceil(Runtime.getRuntime.availableProcessors() / 4f).toInt) | ||
|
|
||
| private val logDir = conf.getOption("spark.history.fs.logDirectory") | ||
| .map { d => Utils.resolveURI(d).toString } | ||
| .getOrElse(DEFAULT_LOG_DIR) | ||
|
|
@@ -129,11 +135,11 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) | |
| } | ||
|
|
||
| /** | ||
| * An Executor to fetch and parse log files. | ||
| * Fixed size thread pool to fetch and parse log files. | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should update the description since no longer a single Executor
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
| private val replayExecutor: ExecutorService = { | ||
| if (!conf.contains("spark.testing")) { | ||
| ThreadUtils.newDaemonSingleThreadExecutor("log-replay-executor") | ||
| ThreadUtils.newDaemonFixedThreadPool(NUM_PROCESSING_THREADS, "log-replay-executor") | ||
| } else { | ||
| MoreExecutors.sameThreadExecutor() | ||
| } | ||
|
|
@@ -297,10 +303,9 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) | |
| if (logInfos.nonEmpty) { | ||
| logDebug(s"New/updated attempts found: ${logInfos.size} ${logInfos.map(_.getPath)}") | ||
| } | ||
| logInfos.grouped(20) | ||
| .map { batch => | ||
| logInfos.map { file => | ||
| replayExecutor.submit(new Runnable { | ||
| override def run(): Unit = mergeApplicationListing(batch) | ||
| override def run(): Unit = mergeApplicationListing(file) | ||
| }) | ||
| } | ||
| .foreach { task => | ||
|
|
@@ -385,9 +390,8 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) | |
| /** | ||
| * Replay the log files in the list and merge the list of old applications with new ones | ||
| */ | ||
| private def mergeApplicationListing(logs: Seq[FileStatus]): Unit = { | ||
| val newAttempts = logs.flatMap { fileStatus => | ||
| try { | ||
| private def mergeApplicationListing(fileStatus: FileStatus): Unit = { | ||
| val newAttempts = try { | ||
| val bus = new ReplayListenerBus() | ||
| val res = replay(fileStatus, bus) | ||
| res match { | ||
|
|
@@ -403,7 +407,6 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) | |
| e) | ||
| None | ||
| } | ||
| } | ||
|
|
||
| if (newAttempts.isEmpty) { | ||
| return | ||
|
|
@@ -413,45 +416,48 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock) | |
| // contains both the new app attempt, and those that were already loaded in the existing apps | ||
| // map. If an attempt has been updated, it replaces the old attempt in the list. | ||
| val newAppMap = new mutable.HashMap[String, FsApplicationHistoryInfo]() | ||
| newAttempts.foreach { attempt => | ||
| val appInfo = newAppMap.get(attempt.appId) | ||
| .orElse(applications.get(attempt.appId)) | ||
| .map { app => | ||
| val attempts = | ||
| app.attempts.filter(_.attemptId != attempt.attemptId).toList ++ List(attempt) | ||
| new FsApplicationHistoryInfo(attempt.appId, attempt.name, | ||
| attempts.sortWith(compareAttemptInfo)) | ||
| } | ||
| .getOrElse(new FsApplicationHistoryInfo(attempt.appId, attempt.name, List(attempt))) | ||
| newAppMap(attempt.appId) = appInfo | ||
| } | ||
|
|
||
| // Merge the new app list with the existing one, maintaining the expected ordering (descending | ||
| // end time). Maintaining the order is important to avoid having to sort the list every time | ||
| // there is a request for the log list. | ||
| val newApps = newAppMap.values.toSeq.sortWith(compareAppInfo) | ||
| val mergedApps = new mutable.LinkedHashMap[String, FsApplicationHistoryInfo]() | ||
| def addIfAbsent(info: FsApplicationHistoryInfo): Unit = { | ||
| if (!mergedApps.contains(info.id)) { | ||
| mergedApps += (info.id -> info) | ||
| applications.synchronized { | ||
| newAttempts.foreach { attempt => | ||
| val appInfo = newAppMap.get(attempt.appId) | ||
| .orElse(applications.get(attempt.appId)) | ||
| .map { app => | ||
| val attempts = | ||
| app.attempts.filter(_.attemptId != attempt.attemptId) ++ List(attempt) | ||
| new FsApplicationHistoryInfo(attempt.appId, attempt.name, | ||
| attempts.sortWith(compareAttemptInfo)) | ||
| } | ||
| .getOrElse(new FsApplicationHistoryInfo(attempt.appId, attempt.name, List(attempt))) | ||
| newAppMap(attempt.appId) = appInfo | ||
| } | ||
| } | ||
|
|
||
| val newIterator = newApps.iterator.buffered | ||
| val oldIterator = applications.values.iterator.buffered | ||
| while (newIterator.hasNext && oldIterator.hasNext) { | ||
| if (newAppMap.contains(oldIterator.head.id)) { | ||
| oldIterator.next() | ||
| } else if (compareAppInfo(newIterator.head, oldIterator.head)) { | ||
| addIfAbsent(newIterator.next()) | ||
| } else { | ||
| addIfAbsent(oldIterator.next()) | ||
| // Merge the new app list with the existing one, maintaining the expected ordering (descending | ||
| // end time). Maintaining the order is important to avoid having to sort the list every time | ||
| // there is a request for the log list. | ||
| val newApps = newAppMap.values.toSeq.sortWith(compareAppInfo) | ||
| val mergedApps = new mutable.LinkedHashMap[String, FsApplicationHistoryInfo]() | ||
| def addIfAbsent(info: FsApplicationHistoryInfo): Unit = { | ||
| if (!mergedApps.contains(info.id)) { | ||
| mergedApps += (info.id -> info) | ||
| } | ||
| } | ||
| } | ||
| newIterator.foreach(addIfAbsent) | ||
| oldIterator.foreach(addIfAbsent) | ||
|
|
||
| applications = mergedApps | ||
| val newIterator = newApps.iterator.buffered | ||
| val oldIterator = applications.values.iterator.buffered | ||
| while (newIterator.hasNext && oldIterator.hasNext) { | ||
| if (newAppMap.contains(oldIterator.head.id)) { | ||
| oldIterator.next() | ||
| } else if (compareAppInfo(newIterator.head, oldIterator.head)) { | ||
| addIfAbsent(newIterator.next()) | ||
| } else { | ||
| addIfAbsent(oldIterator.next()) | ||
| } | ||
| } | ||
| newIterator.foreach(addIfAbsent) | ||
| oldIterator.foreach(addIfAbsent) | ||
|
|
||
| applications = mergedApps | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
How about calling this spark.history.fs.numReplayThreads.
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.
renamed.