apache-spark - 在集群模式下读取文本文件时出现异常
问题描述
我使用 spark 读取了一个文本文件并将其保存在 JavaRDD 中,并尝试打印保存在 RDD 中的数据。我在一个主服务器和两个从服务器的集群中运行我的代码。但是我遇到了异常,例如容器超过阈值,同时遍历 RDD。该代码在独立模式下完美运行。
我的代码:
SparkContext sc = new SparkContext("spark://master.com:7077","Spark-Phoenix");
JavaSparkContext jsc = new JavaSparkContext(sc);
JavaRDD<String> trs_testing = jsc.textFile("hdfs://master.com:9000/Table/sample");
//using iterator
Iterator<String> iStr= trs_testing.toLocalIterator();
while(iStr.hasNext()){ //here I am getting exception
System.out.println("itr next : " + iStr.next());
}
//using foreach()
trs_testing.foreach(new VoidFunction<String>() {//here I am getting exception
private static final long serialVersionUID = 1L;
@Override public void call(String line) throws Exception {
System.out.println(line);
}
});
//using collect()
for(String line:trs_testing.collect()){//here I am getting exception
System.out.println(line);
}
//using foreachPartition()
trs_testing.foreachPartition(new VoidFunction<Iterator<String>>() {//here I am getting exception
private static final long serialVersionUID = 1L;
@Override public void call(Iterator<String> arg0) throws Exception {
while (arg0.hasNext()) {
String line = arg0.next();
System.out.println(line);
}
}
});
例外:
ERROR TaskSchedulerImpl Lost executor 0 on master.com: Remote RPC client dis associated。可能是由于容器超过阈值, 或网络问题。检查驱动程序日志以获取 WARN 消息。错误 TaskSchedulerImpl 在 slave1.com 上丢失了执行程序 1:远程 RPC 客户端已解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。错误 TaskSchedulerImpl 在 master.com 上丢失了执行程序 2:远程 RPC 客户端已解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。slave2.com 上的错误 TaskSchedulerImpl 丢失执行程序 3:远程 RPC 客户端已解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。ERROR TaskSetManager Task 0 in stage 0.0 失败 4 次;线程“主”org.apache.spark.SparkException 中的中止作业异常:作业因阶段失败而中止:阶段 0 中的任务 0。0 失败 4 次,最近一次失败:在 0.0 阶段丢失任务 0.3(TID 3,slave1.com):ExecutorLostFailure(由于其中一个正在运行的任务导致执行器 3 退出) 原因:远程 RPC 客户端解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。驱动程序堆栈跟踪:在 org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1 的 org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1454)。在 scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala: 59)在 scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) 在 org。
解决方案
我得到了解决方案。我正在通过我的机器执行代码,而我的主从服务器正在远程服务器上运行。我将代码导出到远程服务器并最终能够处理数据。
推荐阅读
- python - python pandas - 处理嵌套 groupby 的最佳方法
- r - R/ggplot2:添加带有透明度信息的 png
- excel - 仅将范围设置为另一个范围的可见单元格
- reactjs - 尝试从合约 A 部署合约 B,出现错误:无法存储合约代码,请检查您的 gas 限制。?
- list - Tcl 拆分列表中的列表元素
- python - 我无法使用 pywebcopy 下载完整的网页
- typescript - 为什么 Typescript 会为同一个变量推断不同的类型?
- haskell - 声明函数类型时语法不一致
- android - 在 Android 的 Kotlin 中,我需要一个查找表,在运行时从中选择一个数字。如何从资源中获取此表?
- python - 当我输入一个带有数字平方的大表达式时,eval() 函数会停止程序。Python