Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/8340#discussion_r37599461
--- Diff:
streaming/src/main/scala/org/apache/spark/streaming/scheduler/ReceiverSchedulingPolicy.scala
---
@@ -144,27 +141,31 @@ private[streaming] class ReceiverSchedulingPolicy {
val scheduledExecutors = mutable.Set[String]()
scheduledExecutors ++= preferredLocation
- val executorWeights = receiverTrackingInfoMap.values.flatMap {
receiverTrackingInfo =>
- receiverTrackingInfo.state match {
- case ReceiverState.INACTIVE => Nil
- case ReceiverState.SCHEDULED =>
- val scheduledExecutors =
receiverTrackingInfo.scheduledExecutors.get
- // The probability that a scheduled receiver will run in an
executor is
- // 1.0 / scheduledLocations.size
- scheduledExecutors.map(location => location -> (1.0 /
scheduledExecutors.size))
- case ReceiverState.ACTIVE =>
Seq(receiverTrackingInfo.runningExecutor.get -> 1.0)
- }
+ val executorWeights = receiverTrackingInfoMap.filter(_._1 !=
receiverId).values.flatMap {
+ receiverTrackingInfo =>
+ receiverTrackingInfo.state match {
+ case ReceiverState.INACTIVE => Nil
+ case ReceiverState.SCHEDULED =>
+ val scheduledExecutors =
receiverTrackingInfo.scheduledExecutors.get
+ // The probability that a scheduled receiver will run in an
executor is
+ // 1.0 / scheduledLocations.size
+ scheduledExecutors.map(location => location -> (1.0 /
scheduledExecutors.size))
+ case ReceiverState.ACTIVE =>
Seq(receiverTrackingInfo.runningExecutor.get -> 1.0)
+ }
}.groupBy(_._1).mapValues(_.map(_._2).sum) // Sum weights for each
executor
- val idleExecutors = (executors.toSet -- executorWeights.keys).toSeq
- if (idleExecutors.size >= preferredNumExecutors) {
- // If there are more than `preferredNumExecutors` idle executors,
return all of them
+ val idleExecutors = executors.toSet -- executorWeights.keys
+ if (idleExecutors.nonEmpty) {
scheduledExecutors ++= idleExecutors
} else {
- // If there are less than `preferredNumExecutors` idle executors,
return 3 best options
- scheduledExecutors ++= idleExecutors
- val sortedExecutors = executorWeights.toSeq.sortBy(_._2).map(_._1)
- scheduledExecutors ++= (idleExecutors ++
sortedExecutors).take(preferredNumExecutors)
+ // There is no idle executor. So select all executors that have the
minimum weight.
+ val sortedExecutors = executorWeights.toSeq.sortBy(_._2)
+ if (sortedExecutors.nonEmpty) {
+ val minWeight = sortedExecutors(0)._2
+ scheduledExecutors ++= sortedExecutors.takeWhile(_._2 ==
minWeight).map(_._1)
+ } else {
+ // This should not happen since "executors" is not empty
--- End diff --
Are you talking about `executorWeights no being empty?
And why it cannot be empty? Is it because that by the time
`rescheduleReceiver` is called, all the receivers have already been scheduling
by `scheduleReceivers` which means that there are some weights for at some
executors?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]