squito commented on a change in pull request #23951: [SPARK-13704][CORE][YARN]
Re-implement RackResolver to reduce resolving time
URL: https://github.com/apache/spark/pull/23951#discussion_r266546327
##########
File path:
core/src/test/scala/org/apache/spark/scheduler/TaskSetManagerSuite.scala
##########
@@ -1602,4 +1611,50 @@ class TaskSetManagerSuite extends SparkFunSuite with
LocalSparkContext with Logg
verify(sched.dagScheduler).taskEnded(manager.tasks(3), Success,
result.value(),
result.accumUpdates, info3)
}
+
+ test("SPARK-27038 Verify the rack resolving time has been reduced") {
+ sc = new SparkContext("local", "test")
+ for (i <- 0 to 99) {
+ FakeRackUtil.assignHostToRack("host" + i, "rack" + (i % 20))
+ }
+ sched = new FakeTaskScheduler(sc,
+ ("execA", "host1"), ("execB", "host2"), ("execC", "host3"))
+ val locations = new ArrayBuffer[Seq[TaskLocation]]()
+ for (i <- 0 to 99) {
+ locations += Seq(TaskLocation("host" + i))
+ }
+ val taskSet = FakeTask.createTaskSet(100, locations: _*)
+ val clock = new ManualClock
+ val manager = new TaskSetManager(sched, taskSet, MAX_TASK_FAILURES, clock
= clock)
+ var total = 0
+ for (i <- 0 until 20) {
+ val numTaskInRack = manager.getPendingTasksForRack("rack" + i).length
Review comment:
I think this check is the only reason you are expanding the visibility of
`getPendingTasksForRack` (and an equivalent check in the other test). While
this is a bit of a pain, I think you can leave that as an internal
implementation detail, totally `private`, and instead check the response to
various `resourceOffers`, as is done in the other tests here. Eg. something
like (untested)
```scala
val conf = new SparkConf()
.set(config.LOCALITY_WAIT.key, "0")
.set(config.LOCALITY_WAIT_RACK.key, "1s")
sc = new SparkContext("local", "test", conf)
// Create a cluster with 20 racks, with hosts spread out among them
val execAndHost = (0 to 199).map { i =>
FakeRackUtil.assignHostToRack("host" + i, "rack" + (i % 20))
("exec" + i, "host" + i)
}
sched = new FakeTaskScheduler(sc, execAndHost: _*)
// make a taskset with preferred locations on the first 100 hosts in our
cluster
...
val clock = new ManualClock
val manager = new TaskSetManager(sched, taskSet, MAX_TASK_FAILURES, clock =
clock)
// with rack locality, reject an offer on a host with an unknown rack
assert(manager.resourceOffer("otherExec", "otherHost",
TaskLocality.RACK_LOCAL).isEmpty)
(0 until 20).foreach { rackIdx =>
(0 until 5).foreach { offerIdx =>
// if we offer hosts which are not in preferred locations, we'll reject
them at NODE_LOCAL level,
// but accept them at RACK_LOCAL level if they're on OK racks
val hostIdx = 100 + rackIdx
assert(manger.resourceOffer("exec" + hostIdx, "host" + hostIdx,
TaskLocality.NODE_LOCAL).isEmpty)
assert(manger.resourceOffer("exec" + hostIdx, "host" + hostIdx,
TaskLocality.RACK_LOCAL).isDefined)
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]