-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19605][DStream] Fail it if existing resource is not enough to run streaming job #16936
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import scala.util.{Failure, Success} | |
|
|
||
| import org.apache.spark._ | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config._ | ||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.rpc._ | ||
| import org.apache.spark.scheduler.{ExecutorCacheTaskLocation, TaskLocation} | ||
|
|
@@ -260,7 +261,7 @@ class ReceiverTracker(ssc: StreamingContext, skipReceiverLaunch: Boolean = false | |
| } | ||
|
|
||
| def numReceivers(): Int = { | ||
| receiverInputStreams.size | ||
| receiverInputStreams.length | ||
| } | ||
|
|
||
| /** Register a receiver */ | ||
|
|
@@ -436,6 +437,74 @@ class ReceiverTracker(ssc: StreamingContext, skipReceiverLaunch: Boolean = false | |
| assert(getExecutors.nonEmpty) | ||
| } | ||
|
|
||
| /** | ||
| * Check if existing resource is enough to run job. | ||
| */ | ||
| private def checkResourceValid(): Unit = { | ||
| val coresPerTask = ssc.conf.get(CPUS_PER_TASK) | ||
|
|
||
| def localCpuCount: Int = Runtime.getRuntime.availableProcessors() | ||
|
|
||
| ssc.conf.get("spark.master") match { | ||
| case m if m.startsWith("yarn") => | ||
| val numCoresPerExecutor = ssc.conf.get(EXECUTOR_CORES) | ||
| val numExecutors = getTargetExecutorNumber() | ||
| if (numExecutors * numCoresPerExecutor / coresPerTask < numReceivers) { | ||
| throw new SparkException("There are no enough resource to run Spark Streaming job: " + | ||
| s"existing resource can only be used to scheduler some of receivers." + | ||
| s"$numExecutors executors, $numCoresPerExecutor cores per executor, $coresPerTask " + | ||
| s"cores per task and $numReceivers receivers.") | ||
| } | ||
| case m if m.startsWith("spark") || m.startsWith("mesos") => | ||
| val coresMax = ssc.conf.get(CORES_MAX).getOrElse(0) | ||
| if (coresMax / coresPerTask < numReceivers) { | ||
| throw new SparkException("There are no enough resource to run Spark Streaming job: " + | ||
| s"existing resource can only be used to scheduler some of receivers." + | ||
| s"$coresMax cores totally, $coresPerTask cores per task and $numReceivers receivers.") | ||
| } | ||
| case m if m.startsWith("local") => | ||
| m match { | ||
| case "local" => | ||
| throw new SparkException("There are no enough resource to run Spark Streaming job.") | ||
| case SparkMasterRegex.LOCAL_N_REGEX(threads) => | ||
| val threadCount = if (threads == "*") localCpuCount else threads.toInt | ||
| if (threadCount / coresPerTask < numReceivers) { | ||
| throw new SparkException("There are no enough resource to run Spark Streaming job: " + | ||
| s"existing resource can only be used to scheduler some of receivers." + | ||
| s"$threadCount threads, $coresPerTask threads per task and $numReceivers " + | ||
| s"receivers.") | ||
| } | ||
| case SparkMasterRegex.LOCAL_N_FAILURES_REGEX(threads, maxFailures) => | ||
| val threadCount = if (threads == "*") localCpuCount else threads.toInt | ||
| if (threadCount / coresPerTask < numReceivers) { | ||
| throw new SparkException("There are no enough resource to run Spark Streaming job: " + | ||
| s"existing resource can only be used to scheduler some of receivers." + | ||
| s"$threadCount threads, $coresPerTask threads per task and $numReceivers " + | ||
| s"receivers.") | ||
| } | ||
| case SparkMasterRegex.LOCAL_CLUSTER_REGEX(numSlaves, coresPerSlave, memoryPerSlave) => | ||
| val coresMax = numSlaves.toInt * coresPerSlave.toInt | ||
| if (coresMax / coresPerTask < numReceivers) { | ||
| throw new SparkException("There are no enough resource to run Spark Streaming job: " + | ||
| s"existing resource can only be used to scheduler some of receivers." + | ||
| s"$numSlaves slaves, $coresPerSlave cores per slave, $coresPerTask " + | ||
| s"cores per task and $numReceivers receivers.") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private def getTargetExecutorNumber(): Int = { | ||
| if (Utils.isDynamicAllocationEnabled(ssc.conf)) { | ||
| ssc.conf.get(DYN_ALLOCATION_MAX_EXECUTORS) | ||
| } else { | ||
| val targetNumExecutors = | ||
| sys.env.get("SPARK_EXECUTOR_INSTANCES").map(_.toInt).getOrElse(2) | ||
| // System property can override environment variable. | ||
|
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. here "2" refers to "YarnSparkHadoopUtil.DEFAULT_NUMBER_EXECUTORS" |
||
| ssc.conf.get(EXECUTOR_INSTANCES).getOrElse(targetNumExecutors) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the receivers from the ReceiverInputDStreams, distributes them to the | ||
| * worker nodes as a parallel collection, and runs them. | ||
|
|
@@ -447,6 +516,8 @@ class ReceiverTracker(ssc: StreamingContext, skipReceiverLaunch: Boolean = false | |
| rcvr | ||
| } | ||
|
|
||
| checkResourceValid() | ||
|
|
||
| runDummySparkJob() | ||
|
|
||
| logInfo("Starting " + receivers.length + " receivers") | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -837,6 +837,26 @@ class StreamingContextSuite extends SparkFunSuite with BeforeAndAfter with Timeo | |
| assert(latch.await(60, TimeUnit.SECONDS)) | ||
| } | ||
|
|
||
| for (master <- Array("local", "local[1]", "local[1, 2]", "local-cluster[1, 1, 1024]")) { | ||
| test(s"check resource enough for $master") { | ||
| val conf = new SparkConf().setMaster(master).setAppName(appName) | ||
| ssc = new StreamingContext(conf, Milliseconds(100)) | ||
| val input1 = ssc.receiverStream(new TestReceiver) | ||
| val input2 = ssc.receiverStream(new TestReceiver) | ||
| val input = input1.union(input2) | ||
|
|
||
| try { | ||
| input.foreachRDD { rdd => rdd.count()} | ||
| ssc.start() | ||
| ssc.awaitTerminationOrTimeout(60000) | ||
| assert(false, "There are no enough resource to run Spark Streaming job.") | ||
| } catch { | ||
| case e: SparkException => | ||
| // expected. | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def addInputStream(s: StreamingContext): DStream[Int] = { | ||
| val input = (1 to 100).map(i => 1 to i) | ||
| val inputStream = new TestInputStream(s, input, 1) | ||
|
|
@@ -938,7 +958,7 @@ object SlowTestReceiver { | |
| /** Streaming application for testing DStream and RDD creation sites */ | ||
| package object testPackage extends Assertions { | ||
| def test() { | ||
| val conf = new SparkConf().setMaster("local").setAppName("CreationSite test") | ||
| val conf = new SparkConf().setMaster("local[2]").setAppName("CreationSite test") | ||
| val ssc = new StreamingContext(conf, Milliseconds(100)) | ||
|
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. unit test fail here |
||
| try { | ||
| val inputStream = ssc.receiverStream(new TestReceiver) | ||
|
|
||
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.
multi-definition error in ApplicationMaster.scala, remove this as we add it in core