Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.{SparkException, SparkFunSuite}
import org.apache.spark.resource.ResourceAmountUtils
import org.apache.spark.resource.ResourceUtils.GPU

class ExecutorResourceInfoSuite extends SparkFunSuite {
class ExecutorResourceInfoSuite extends SparkFunSuite with ExecutorResourceUtils {

implicit def convertMapLongToDouble(resources: Map[String, Long]): Map[String, Double] = {
resources.map { case (k, v) => k -> ResourceAmountUtils.toFractionalResource(v) }
Expand Down Expand Up @@ -126,14 +126,6 @@ class ExecutorResourceInfoSuite extends SparkFunSuite {
}
}

def compareMaps(lhs: Map[String, Double], rhs: Map[String, Double],
eps: Double = 0.00000001): Boolean = {
lhs.size == rhs.size &&
lhs.zip(rhs).forall { case ((lName, lAmount), (rName, rAmount)) =>
lName == rName && (lAmount - rAmount).abs < eps
}
}

test("assign/release resource for different task requirements") {
val execInfo = new ExecutorResourceInfo("gpu", Seq("0", "1", "2", "3"))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.spark.scheduler

trait ExecutorResourceUtils {

def compareMaps(lhsMap: Map[String, Double], rhsMap: Map[String, Double],
eps: Double = 0.00000001): Boolean = {
val lhs = lhsMap.toSeq.sorted
val rhs = rhsMap.toSeq.sorted
lhs.size == rhs.size &&
lhs.zip(rhs).forall { case ((lName, lAmount), (rName, rAmount)) =>
lName == rName && (lAmount - rAmount).abs < eps
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

lhs.size == rhs.size && lhs.forall { case (lName, lAmount) =>
  rhs.get(lName).exists(rAmount => (lAmount - rAmount).abs < eps)
}

we can avoid sort this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Thx. Done.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.{SparkException, SparkFunSuite}
import org.apache.spark.resource.{ResourceAmountUtils, ResourceProfileBuilder, TaskResourceRequests}
import org.apache.spark.resource.ResourceUtils.GPU

class ExecutorResourcesAmountsSuite extends SparkFunSuite {
class ExecutorResourcesAmountsSuite extends SparkFunSuite with ExecutorResourceUtils {

implicit def toFractionalResource(resources: Map[String, Long]): Map[String, Double] =
resources.map { case (k, v) => k -> ResourceAmountUtils.toFractionalResource(v) }
Expand All @@ -39,14 +39,6 @@ class ExecutorResourcesAmountsSuite extends SparkFunSuite {
k -> ResourceAmountUtils.toInternalResource(v) }
}

def compareMaps(lhs: Map[String, Double], rhs: Map[String, Double],
eps: Double = 0.00000001): Boolean = {
lhs.size == rhs.size &&
lhs.zip(rhs).forall { case ((lName, lAmount), (rName, rAmount)) =>
lName == rName && (lAmount - rAmount).abs < eps
}
}

test("assign to rp without task resources requirement") {
val executorsInfo = Map(
"gpu" -> new ExecutorResourceInfo("gpu", Seq("2", "4", "6")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2285,9 +2285,9 @@ class TaskSchedulerImplSuite extends SparkFunSuite with LocalSparkContext
config.EXECUTOR_CORES.key -> executorCpus.toString)

val taskSet = if (barrierMode) {
FakeTask.createTaskSet(100)
} else {
FakeTask.createBarrierTaskSet(4 * taskNum)
} else {
FakeTask.createTaskSet(100)
}

val resources = new ExecutorResourcesAmounts(
Expand Down Expand Up @@ -2331,9 +2331,9 @@ class TaskSchedulerImplSuite extends SparkFunSuite with LocalSparkContext
config.EXECUTOR_CORES.key -> executorCpus.toString)

val taskSet = if (barrierMode) {
FakeTask.createTaskSet(100)
} else {
FakeTask.createBarrierTaskSet(4 * taskNum)
} else {
FakeTask.createTaskSet(100)
}

val workerOffers =
Expand Down Expand Up @@ -2390,9 +2390,9 @@ class TaskSchedulerImplSuite extends SparkFunSuite with LocalSparkContext
taskScheduler.sc.resourceProfileManager.addResourceProfile(rp)

val taskSet = if (barrierMode) {
FakeTask.createTaskSet(100, 0, 1, 1, rp.id)
} else {
FakeTask.createBarrierTaskSet(4 * taskNum, 0, 1, 1, rp.id)
} else {
FakeTask.createTaskSet(100, 0, 1, 1, rp.id)
}
val resources = new ExecutorResourcesAmounts(
Map(GPU -> toInternalResource(Map("0" -> 1.0, "1" -> 1.0, "2" -> 1.0, "3" -> 1.0))))
Expand Down Expand Up @@ -2438,9 +2438,9 @@ class TaskSchedulerImplSuite extends SparkFunSuite with LocalSparkContext
taskScheduler.sc.resourceProfileManager.addResourceProfile(rp)

val taskSet = if (barrierMode) {
FakeTask.createTaskSet(100, 0, 1, 1, rp.id)
} else {
FakeTask.createBarrierTaskSet(4 * taskNum, 0, 1, 1, rp.id)
} else {
FakeTask.createTaskSet(100, 0, 1, 1, rp.id)
}

val workerOffers =
Expand Down