복붙노트

[HADOOP] Spark - 스파크 작업에 얼마나 많은 집행자와 코어가 할당되어 있습니까?

HADOOP

Spark - 스파크 작업에 얼마나 많은 집행자와 코어가 할당되어 있습니까?

Spark 아키텍처는 전 집행 인 및 코어의 개념을 중심으로 전개됩니다. 클러스터에서 실행되는 스파크 애플리케이션을 실행하는 실행 프로그램과 코어가 실제로 얼마나 많은지보고 싶습니다.

내 응용 프로그램에서 아래 스 니펫을 사용하려고했지만 행운이 없었습니다.

val conf = new SparkConf().setAppName("ExecutorTestJob")
val sc = new SparkContext(conf)
conf.get("spark.executor.instances")
conf.get("spark.executor.cores")

거기에 SparkContext 개체 또는 SparkConf 개체 등을 사용하여 그 값을 얻을 수있는 방법이 있나요?

해결법

  1. ==============================

    1.getExecutorStorageStatus 및 getExecutorMemoryStatus는 모두 드라이버를 포함하여 실행 프로그램의 수를 반환합니다. 아래 예와 같은 스 니펫.

    getExecutorStorageStatus 및 getExecutorMemoryStatus는 모두 드라이버를 포함하여 실행 프로그램의 수를 반환합니다. 아래 예와 같은 스 니펫.

    /** Method that just returns the current active/registered executors
            * excluding the driver.
            * @param sc The spark context to retrieve registered executors.
            * @return a list of executors each in the form of host:port.
            */
           def currentActiveExecutors(sc: SparkContext): Seq[String] = {
             val allExecutors = sc.getExecutorMemoryStatus.map(_._1)
             val driverHost: String = sc.getConf.get("spark.driver.host")
             allExecutors.filter(! _.split(":")(0).equals(driverHost)).toList
           }
    
    sc.getConf.getInt("spark.executor.instances", 1)
    

    마찬가지로 모든 속성을 가져 와서 아래와 같이 인쇄하면 코어 정보도 얻을 수 있습니다.

    sc.getConf.getAll.mkString("\n")
    

    또는

    sc.getConf.toDebugString
    

    spark.executor.cores가 executor 인 경우 spark.driver.cores 드라이버가이 값을 가져야합니다.

    위 메소드 getExecutorStorageStatus 및 getExecutorMemoryStatus에서 Python API가 구현되지 않았습니다.

    편집하다 SparkSession에서 노출 된 Py4J 바인딩을 사용하여 액세스 할 수 있습니다.

    sc._jsc.sc (). getExecutorMemoryStatus ()

  2. ==============================

    2.이것은 오래된 질문이지만, 이것은 Spark 2.3.0에서 이것을 알아내는 코드입니다.

    이것은 오래된 질문이지만, 이것은 Spark 2.3.0에서 이것을 알아내는 코드입니다.

    + 414     executor_count = len(spark.sparkContext._jsc.sc().statusTracker().getExecutorInfos()) - 1
    + 415     cores_per_executor = int(spark.sparkContext.getConf().get('spark.executor.cores','1'))
    
  3. ==============================

    3.이것은 코어의 수를 얻기위한 파이썬 예제입니다 (마스터 포함).     def workername () :     가져 오기 소켓     return str (socket.gethostname ()) anrdd = sc.parallelize ([ '', '']) namesRDD = anrdd.flatMap (lambda : (1, 작업 이름 ())) namesRDD.count ()

    이것은 코어의 수를 얻기위한 파이썬 예제입니다 (마스터 포함).     def workername () :     가져 오기 소켓     return str (socket.gethostname ()) anrdd = sc.parallelize ([ '', '']) namesRDD = anrdd.flatMap (lambda : (1, 작업 이름 ())) namesRDD.count ()

  4. from https://stackoverflow.com/questions/39162063/spark-how-many-executors-and-cores-are-allocated-to-my-spark-job by cc-by-sa and MIT license