【发布时间】:2018-08-29 19:52:44
【问题描述】:
我正在尝试创建一个 spark 应用程序,它采用 lat、long、timestamp 点的数据集,如果它们增加单元格计数位于网格单元内。网格由以 lon、lat 和 time 为 z 轴的 3d 单元格组成。
现在我已经完成了应用程序,它完成了它应该做的事情,但是扫描整个数据集需要几个小时(~9g)。我的集群由 3 个节点组成,每个节点有 4 个核心,每个 8g ram,我目前使用 6 个执行器,每个执行器有 1 个核心和 2g。
我猜我可以对代码进行相当多的优化,但我的代码中是否存在导致这种延迟的大错误?
//Create a JavaPairRDD with tuple elements. For each String line of lines we split the string
//and assign latitude, longitude and timestamp of each line to sdx,sdy and sdt. Then we check if the data point of
//that line is contained in a cell of the centroids list. If it is then a new tuple is returned
//with key the latitude, Longitude and timestamp (split by ",") of that cell and value 1.
JavaPairRDD<String, Integer> pairs = lines.mapToPair(x -> {
String sdx = x.split(" ")[2];
String sdy = x.split(" ")[3];
String sdt = x.split(" ")[0];
double dx = Double.parseDouble(sdx);
double dy = Double.parseDouble(sdy);
int dt = Integer.parseInt(sdt);
List<Integer> t = brTime.getValue();
List<Point2D.Double> p = brCoo.getValue();
double dist = brDist.getValue();
int dur = brDuration.getValue();
for(int timeCounter=0; timeCounter<t.size(); timeCounter++) {
for ( int cooCounter=0; cooCounter < p.size(); cooCounter++) {
double cx = p.get(cooCounter).getX();
double cy = p.get(cooCounter).getY();
int ct = t.get(timeCounter);
String scx = Double.toString(cx);
String scy = Double.toString(cy);
String sct = Integer.toString(ct);
if (dx > (cx-dist) && dx <= (cx+dist)) {
if (dy > (cy-dist) && dy <= (cy+dist)) {
if (dt > (ct-dur) && dt <= (ct+dur)) {
return new Tuple2<String, Integer>(scx+","+scy+","+sct,1);
}
}
}
}
}
return new Tuple2<String, Integer>("Out Of Bounds",1);
});
【问题讨论】:
标签: java apache-spark cluster-computing