Skip to content

Commit

Permalink
add totalCores
Browse files Browse the repository at this point in the history
  • Loading branch information
allwefantasy committed Dec 4, 2018
1 parent 720bcc4 commit e3ea622
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.apache.spark

import net.csdn.common.reflect.ReflectHelper
import org.apache.spark.scheduler.cluster.{CoarseGrainedSchedulerBackend, StandaloneSchedulerBackend}
import org.apache.spark.scheduler.local.LocalSchedulerBackend
import org.apache.spark.sql.SparkSession

/**
Expand All @@ -17,8 +20,16 @@ class SparkInstanceService(session: SparkSession) {
totalMemory += -1

}
SparkInstanceResource(totalTasks, totalUsedMemory, totalMemory)
val totalCores = session.sparkContext.schedulerBackend match {
case sb: CoarseGrainedSchedulerBackend =>
ReflectHelper.field(sb, "totalCoreCount").asInstanceOf[Int]
case sb: LocalSchedulerBackend =>
java.lang.Runtime.getRuntime.availableProcessors
case sb: StandaloneSchedulerBackend =>
-1
}
SparkInstanceResource(totalCores.toLong, totalTasks, totalUsedMemory, totalMemory)
}
}

case class SparkInstanceResource(totalTasks: Long, totalUsedMemory: Long, totalMemory: Long)
case class SparkInstanceResource(totalCores: Long, totalTasks: Long, totalUsedMemory: Long, totalMemory: Long)

0 comments on commit e3ea622

Please sign in to comment.