加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 如何获取当前作业中使用的核心数?

发布时间:2020-12-16 08:44:06 所属栏目:安全 来源:网络整理
导读:SparkContext有getExecutorMemoryStatus方法.但它是Executor的内存状态. 有没有办法获得核心地位?我使用Spark Standalone Cluster. 解决方法 从下面可能选项3是您正在寻找的那个.. 选项1:Spark web ui为我提供有关总核心和已用核心的信息. 选项2:默认值:
SparkContext有getExecutorMemoryStatus方法.但它是Executor的内存状态.

有没有办法获得核心地位?我使用Spark Standalone Cluster.

解决方法

从下面可能选项3是您正在寻找的那个..

>选项1:Spark web ui为我提供有关总核心和已用核心的信息.

enter image description here

>选项2:默认值:

sc.defaultParallelism通常设置为群集中的工作核心数
>选项3:可以像下面这样使用ExectorInfo.totalCores并尝试……它应该可以工作.

docs说

public class ExecutorInfo extends Object
Stores information about an
executor to pass from the scheduler to SparkListeners.

import org.apache.spark.scheduler.{SparkListener,SparkListenerExecutorAdded}

/**
  * Logs info of added executors.
  */
final class ExecutorLogger extends SparkListener {

  override def onExecutorAdded(executorAdded: SparkListenerExecutorAdded): Unit =
    println(s"rExecutor ${executorAdded.executorId} added: ${executorAdded.executorInfo.executorHost} ${executorAdded.executorInfo.totalCores} cores")

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读