Skip to content

Commit 7614145

Browse files
liyinan926ash211
authored andcommitted
Allow number of executor cores to have fractional values
This commit tries to solve issue #359 by allowing the `spark.executor.cores` configuration key to take fractional values, e.g., 0.5 or 1.5. The value is used to specify the cpu request when creating the executor pods, which is allowed to be fractional by Kubernetes. When the value is passed to the executor process through the environment variable `SPARK_EXECUTOR_CORES`, the value is rounded up to the closest integer as required by the `CoarseGrainedExecutorBackend`. Signed-off-by: Yinan Li <ynli@google.com>(cherry picked from commit 6f6cfd6)
1 parent cda20f5 commit 7614145

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/kubernetes/KubernetesClusterSchedulerBackend.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private[spark] class KubernetesClusterSchedulerBackend(
108108
MEMORY_OVERHEAD_MIN))
109109
private val executorMemoryWithOverhead = executorMemoryMb + memoryOverheadMb
110110

111-
private val executorCores = conf.getOption("spark.executor.cores").getOrElse("1")
111+
private val executorCores = conf.getDouble("spark.executor.cores", 1d)
112112
private val executorLimitCores = conf.getOption(KUBERNETES_EXECUTOR_LIMIT_CORES.key)
113113

114114
private implicit val requestExecutorContext = ExecutionContext.fromExecutorService(
@@ -378,7 +378,7 @@ private[spark] class KubernetesClusterSchedulerBackend(
378378
.withAmount(s"${executorMemoryWithOverhead}M")
379379
.build()
380380
val executorCpuQuantity = new QuantityBuilder(false)
381-
.withAmount(executorCores)
381+
.withAmount(executorCores.toString)
382382
.build()
383383
val executorExtraClasspathEnv = executorExtraClasspath.map { cp =>
384384
new EnvVarBuilder()
@@ -389,7 +389,8 @@ private[spark] class KubernetesClusterSchedulerBackend(
389389
val requiredEnv = Seq(
390390
(ENV_EXECUTOR_PORT, executorPort.toString),
391391
(ENV_DRIVER_URL, driverUrl),
392-
(ENV_EXECUTOR_CORES, executorCores),
392+
// Executor backend expects integral value for executor cores, so round it up to an int.
393+
(ENV_EXECUTOR_CORES, math.ceil(executorCores).toInt.toString),
393394
(ENV_EXECUTOR_MEMORY, executorMemoryString),
394395
(ENV_APPLICATION_ID, applicationId()),
395396
(ENV_EXECUTOR_ID, executorId),

0 commit comments

Comments
 (0)