-
Notifications
You must be signed in to change notification settings - Fork 858
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
Rewrite Spark fetcher/heuristics. #162
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
993896c
Rewrite Spark fetcher/heuristics.
rayortigas f27270e
Force hk2-{utils,locator} to make Travis work.
rayortigas e7541db
Force hk2-{utils,locator} in all configurations to make Travis work.
rayortigas 7404c04
Upgrade SBT to 0.13.2 to avoid issues on Travis.
rayortigas b2c1d8f
Revert forcing of hk2-{utils,locator}, since upgrading SBT to 0.13.2 …
rayortigas 06480a2
After rebasing against master, fix JMockit test that stopped working …
rayortigas 277b9d2
Restore memory waste buffer that Spark metrics aggregator was using.
rayortigas e084b0c
Hide internals of SparkComboApplicationData.
rayortigas a3dde3a
Start removing old fetcher/heuristic code/tests.
rayortigas 7d87aa6
SparkCombo* -> Spark*
rayortigas 6ef8e90
Configure to use new Spark fetcher/heuristics.
rayortigas 4a92bec
Configure to use new Spark fetcher/heuristics.
rayortigas 604a64b
Fix bug from refactoring SparkApplicationData.
rayortigas 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 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
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
53 changes: 53 additions & 0 deletions
53
app/com/linkedin/drelephant/analysis/SeverityThresholds.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,53 @@ | ||
/* | ||
* Copyright 2016 LinkedIn Corp. | ||
* | ||
* Licensed 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 com.linkedin.drelephant.analysis | ||
|
||
import com.linkedin.drelephant.util.Utils | ||
|
||
|
||
/** | ||
* A convenience case class for containing severity thresholds and calculating severity. | ||
*/ | ||
case class SeverityThresholds(low: Number, moderate: Number, severe: Number, critical: Number, ascending: Boolean) { | ||
if (ascending) { | ||
require(low.doubleValue <= moderate.doubleValue) | ||
require(moderate.doubleValue <= severe.doubleValue) | ||
require(severe.doubleValue <= critical.doubleValue) | ||
} else { | ||
require(low.doubleValue >= moderate.doubleValue) | ||
require(moderate.doubleValue >= severe.doubleValue) | ||
require(severe.doubleValue >= critical.doubleValue) | ||
} | ||
|
||
def severityOf(value: Number): Severity = if (ascending) { | ||
Severity.getSeverityAscending(value, low, moderate, severe, critical) | ||
} else { | ||
Severity.getSeverityDescending(value, low, moderate, severe, critical) | ||
} | ||
} | ||
|
||
object SeverityThresholds { | ||
val NUM_THRESHOLDS = 4 | ||
|
||
/** Returns a SeverityThresholds object from a Dr. Elephant configuration string parseable by Utils.getParam(String, int). */ | ||
def parse( | ||
rawString: String, | ||
ascending: Boolean | ||
): Option[SeverityThresholds] = Option(Utils.getParam(rawString, NUM_THRESHOLDS)).map { thresholds => | ||
SeverityThresholds(low = thresholds(0), moderate = thresholds(1), severe = thresholds(2), critical = thresholds(3), ascending) | ||
} | ||
} |
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
120 changes: 120 additions & 0 deletions
120
app/com/linkedin/drelephant/spark/SparkMetricsAggregator.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,120 @@ | ||
/* | ||
* Copyright 2016 LinkedIn Corp. | ||
* | ||
* Licensed 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 com.linkedin.drelephant.spark | ||
|
||
import com.linkedin.drelephant.analysis.{HadoopAggregatedData, HadoopApplicationData, HadoopMetricsAggregator} | ||
import com.linkedin.drelephant.configurations.aggregator.AggregatorConfigurationData | ||
import com.linkedin.drelephant.math.Statistics | ||
import com.linkedin.drelephant.spark.data.{SparkApplicationData, SparkLogDerivedData, SparkRestDerivedData} | ||
import com.linkedin.drelephant.util.MemoryFormatUtils | ||
import org.apache.commons.io.FileUtils | ||
import org.apache.log4j.Logger | ||
import scala.util.Try | ||
|
||
|
||
class SparkMetricsAggregator(private val aggregatorConfigurationData: AggregatorConfigurationData) | ||
extends HadoopMetricsAggregator { | ||
import SparkMetricsAggregator._ | ||
|
||
private val logger: Logger = Logger.getLogger(classOf[SparkMetricsAggregator]) | ||
|
||
private val allocatedMemoryWasteBufferPercentage: Double = | ||
Option(aggregatorConfigurationData.getParamMap.get(ALLOCATED_MEMORY_WASTE_BUFFER_PERCENTAGE_KEY)) | ||
.flatMap { value => Try(value.toDouble).toOption } | ||
.getOrElse(DEFAULT_ALLOCATED_MEMORY_WASTE_BUFFER_PERCENTAGE) | ||
|
||
private val hadoopAggregatedData: HadoopAggregatedData = new HadoopAggregatedData() | ||
|
||
override def getResult(): HadoopAggregatedData = hadoopAggregatedData | ||
|
||
override def aggregate(data: HadoopApplicationData): Unit = data match { | ||
case (data: SparkApplicationData) => aggregate(data) | ||
case _ => throw new IllegalArgumentException("data should be SparkApplicationData") | ||
} | ||
|
||
private def aggregate(data: SparkApplicationData): Unit = for { | ||
executorInstances <- executorInstancesOf(data) | ||
executorMemoryBytes <- executorMemoryBytesOf(data) | ||
} { | ||
val applicationDurationMillis = applicationDurationMillisOf(data) | ||
val totalExecutorTaskTimeMillis = totalExecutorTaskTimeMillisOf(data) | ||
|
||
val resourcesAllocatedMBSeconds = | ||
aggregateResourcesAllocatedMBSeconds(executorInstances, executorMemoryBytes, applicationDurationMillis) | ||
val resourcesUsedMBSeconds = aggregateResourcesUsedMBSeconds(executorMemoryBytes, totalExecutorTaskTimeMillis) | ||
|
||
val resourcesWastedMBSeconds = | ||
((BigDecimal(resourcesAllocatedMBSeconds) * (1.0 - allocatedMemoryWasteBufferPercentage)) - BigDecimal(resourcesUsedMBSeconds)) | ||
.toBigInt | ||
|
||
if (resourcesUsedMBSeconds.isValidLong) { | ||
hadoopAggregatedData.setResourceUsed(resourcesUsedMBSeconds.toLong) | ||
} else { | ||
logger.info(s"resourcesUsedMBSeconds exceeds Long.MaxValue: ${resourcesUsedMBSeconds}") | ||
} | ||
|
||
if (resourcesWastedMBSeconds.isValidLong) { | ||
hadoopAggregatedData.setResourceWasted(resourcesWastedMBSeconds.toLong) | ||
} else { | ||
logger.info(s"resourcesWastedMBSeconds exceeds Long.MaxValue: ${resourcesWastedMBSeconds}") | ||
} | ||
} | ||
|
||
private def aggregateResourcesUsedMBSeconds(executorMemoryBytes: Long, totalExecutorTaskTimeMillis: BigInt): BigInt = { | ||
val bytesMillis = BigInt(executorMemoryBytes) * totalExecutorTaskTimeMillis | ||
(bytesMillis / (BigInt(FileUtils.ONE_MB) * BigInt(Statistics.SECOND_IN_MS))) | ||
} | ||
|
||
private def aggregateResourcesAllocatedMBSeconds( | ||
executorInstances: Int, | ||
executorMemoryBytes: Long, | ||
applicationDurationMillis: Long | ||
): BigInt = { | ||
val bytesMillis = BigInt(executorInstances) * BigInt(executorMemoryBytes) * BigInt(applicationDurationMillis) | ||
(bytesMillis / (BigInt(FileUtils.ONE_MB) * BigInt(Statistics.SECOND_IN_MS))) | ||
} | ||
|
||
private def executorInstancesOf(data: SparkApplicationData): Option[Int] = { | ||
val appConfigurationProperties = data.appConfigurationProperties | ||
appConfigurationProperties.get(SPARK_EXECUTOR_INSTANCES_KEY).map(_.toInt) | ||
} | ||
|
||
private def executorMemoryBytesOf(data: SparkApplicationData): Option[Long] = { | ||
val appConfigurationProperties = data.appConfigurationProperties | ||
appConfigurationProperties.get(SPARK_EXECUTOR_MEMORY_KEY).map(MemoryFormatUtils.stringToBytes) | ||
} | ||
|
||
private def applicationDurationMillisOf(data: SparkApplicationData): Long = { | ||
require(data.applicationInfo.attempts.nonEmpty) | ||
val lastApplicationAttemptInfo = data.applicationInfo.attempts.last | ||
lastApplicationAttemptInfo.endTime.getTime - lastApplicationAttemptInfo.startTime.getTime | ||
} | ||
|
||
private def totalExecutorTaskTimeMillisOf(data: SparkApplicationData): BigInt = { | ||
data.executorSummaries.map { executorSummary => BigInt(executorSummary.totalDuration) }.sum | ||
} | ||
} | ||
|
||
object SparkMetricsAggregator { | ||
/** The percentage of allocated memory we expect to waste because of overhead. */ | ||
val DEFAULT_ALLOCATED_MEMORY_WASTE_BUFFER_PERCENTAGE = 0.5D | ||
|
||
val ALLOCATED_MEMORY_WASTE_BUFFER_PERCENTAGE_KEY = "allocated_memory_waste_buffer_percentage" | ||
|
||
val SPARK_EXECUTOR_INSTANCES_KEY = "spark.executor.instances" | ||
val SPARK_EXECUTOR_MEMORY_KEY = "spark.executor.memory" | ||
} |
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.
use < instead . I can't think of a scenario where it will be equal.
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.
The old code used equal numbers for severe and critical for some thresholds, e.g.
dr-elephant/app/com/linkedin/drelephant/spark/heuristics/JobRuntimeHeuristic.java
Line 47 in dad905c
dr-elephant/app/com/linkedin/drelephant/analysis/Severity.java
Line 150 in dad905c