cpu 使用率低,而 运行 Spark 作业

Low cpu usage while running a spark job

我是 运行 Spark 工作。我有 4 个内核和工作内存设置为 5G。 Application master 在同一网络中的另一台机器上,并且不托管任何 worker。这是我的代码:

private void myClass() {
    // configuration of the spark context
    SparkConf conf = new SparkConf().setAppName("myWork").setMaster("spark://myHostIp:7077").set("spark.driver.allowMultipleContexts", "true");
    // creation of the spark context in wich we will run the algorithm
    JavaSparkContext sc = new JavaSparkContext(conf);

    // algorithm
    for(int i = 0; i<200; i++) {
        System.out.println("===============================================================");
        System.out.println("iteration : " + i);
        System.out.println("===============================================================");
        ArrayList<Boolean> list = new ArrayList<Boolean>();
        for(int j = 0; j < 1900; j++){
            list.add(true);
        }
        JavaRDD<Ant> ratings = sc.parallelize(list, 100)
                    .map(bool -> new myObj())
                    .map(obj -> this.setupObj(obj))
                    .map(obj -> this.moveObj(obj))
                    .cache();
        int[] stuff = ratings
                    .map(obj -> obj.getStuff())
                    .reduce((obj1,obj2)->this.mergeStuff(obj1,obj2));
        this.setStuff(tour);

        ArrayList<TabObj> tabObj = ratings
                    .map(obj -> this.objToTabObjAsTab(obj))
                    .reduce((obj1,obj2)->this.mergeTabObj(obj1,obj2));
        ratings.unpersist(false);

        this.setTabObj(tabObj);
    }

    sc.close();
}

当我启动它时,我可以在 Spark UI 上看到进度,但它真的很慢(我必须将并行化设置得相当高,否则我会遇到超时问题)。我以为是CPU瓶颈,但是JVMCPU消耗其实很低(大部分时候是0%,有时候5%多一点。。。)。

根据监视器,JVM 使用了大约 3G 的内存,只有 19M 缓存。

主控主机4核,内存较少(4G)。那台机器显示 100% CPU 消耗(一个完整的核心),我不明白为什么这么高......它只是必须将分区发送给另一台机器上的工作人员,对吧?

为什么CPU工人消费低,主人消费高?

  1. 确保你已经在集群中通过 Yarn 或 mesos 提交了你的 Spark 作业,否则它可能只会 运行 在你的主节点中。

  2. 由于您的代码非常简单,因此完成计算应该非常快,但我建议使用 wordcount 示例尝试读取几 GB 的输入源来测试 CPU消费看起来像。

  3. 请使用"local[*]"。 * 表示使用所有核心进行计算

    SparkConf sparkConf = new SparkConf().set("spark.driver.host", "localhost").setAppName("unit-testing").setMaster("local[*]"); 参考文献:https://spark.apache.org/docs/latest/configuration.html

  4. 在 spark 中有很多东西会影响 CPU 和内存使用,例如执行器和每个 spark.executor.memory 你喜欢分发。