我正在运行 Spark 作业。我有 4 个核心,工作内存设置为 5G。应用程序主机位于同一网络中的另一台计算机上,并且不托管任何工作程序。这是我的代码:
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 which 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瓶颈,但是JVM的CPU消耗其实很低(大部分时候是0%,有时候5%多一点...)。
根据监视器,JVM 使用了大约 3G 内存,仅缓存了 19M。
主控主机4核,内存较少(4G)。那台机器显示 100% CPU 消耗(一个完整的核心),我不明白为什么这么高...它只需将分区发送给另一台机器上的工作程序,对吗?
为什么worker上CPU消耗低,master上CPU消耗高?
确保您已通过集群中的 Yarn 或 mesos 提交 Spark 作业,否则它可能只在您的主节点中运行。
由于您的代码非常简单,因此完成计算应该非常快,但我建议使用 wordcount 示例尝试读取几 GB 的输入源来测试 CPU 消耗情况。
请使用“本地[*]”。 * 表示使用您的所有核心进行计算
SparkConf SparkConf = new SparkConf().set("spark.driver.host", "localhost").setAppName("单元测试").setMaster("local[*]"); 参考资料:https://spark.apache.org/docs/latest/configuration.html
在spark中,有很多东西可能会影响CPU和内存的使用,例如执行器和您喜欢分配的每个spark.executor.memory。