我目前有下表,表示在hibernate中映射的总线网络,从基于Spring MVC的总线路由规划器访问 我正在尝试让我的路由规划器应用程序执行得更快,我将所有上面的表加载到列表中以执行路由规划器逻辑。
如果有人对如何加快我的表现有任何想法,我将不胜感激 或任何另一种方法的建议来解决处理大量数据的问题
Coordinate Connections Table (INT,INT,INT)( Containing 50,000 Coordinate Connections)
ID, FROMCOORDID, TOCOORDID
1 1 2
2 1 17
3 1 63
4 1 64
5 1 65
6 1 95
Coordinate Table (INT,DECIMAL, DECIMAL) (Containing 4700 Coordinates)
ID , LAT, LNG
0 59.352669 -7.264341
1 59.352669 -7.264341
2 59.350012 -7.260653
3 59.337585 -7.189798
4 59.339221 -7.193582
5 59.341408 -7.205888
Bus Stop Table (INT, INT, INT)(Containing 15000 Stops)
StopID RouteID COORDINATEID
1000100001 100 17
1000100002 100 18
1000100003 100 19
1000100004 100 20
1000100005 100 21
1000100006 100 22
1000100007 100 23
这是从每个表加载所有数据所需的时间:
stop.findAll = 148ms, stops.size: 15670
Hibernate: select coordinate0_.COORDINATEID as COORDINA1_2_, coordinate0_.LAT as LAT2_, coordinate0_.LNG as LNG2_ from COORDINATES coordinate0_
coord.findAll = 51ms , coordinates.size: 4704
Hibernate: select coordconne0_.COORDCONNECTIONID as COORDCON1_3_, coordconne0_.DISTANCE as DISTANCE3_, coordconne0_.FROMCOORDID as FROMCOOR3_3_, coordconne0_.TOCOORDID as TOCOORDID3_ from COORDCONNECTIONS coordconne0_
coordinateConnectionDao.findAll = 238ms ; coordConnectioninates.size:48132
Hibernate Annotations
@Entity
@Table(name = "STOPS")
public class Stop implements Serializable {
@Id
@GeneratedValue
@Column(name = "COORDINATEID")
private Integer CoordinateID;
@Column(name = "LAT")
private double latitude;
@Column(name = "LNG")
private double longitude;
}
@Table(name = "COORDINATES")
public class Coordinate {
@Id
@GeneratedValue
@Column(name = "COORDINATEID")
private Integer CoordinateID;
@Column(name = "LAT")
private double latitude;
@Column(name = "LNG")
private double longitude;
}
@Entity
@Table(name = "COORDCONNECTIONS")
public class CoordConnection {
@Id
@GeneratedValue
@Column(name = "COORDCONNECTIONID")
private Integer CoordinateID;
/**
* From Coordinate_id value
*/
@Column(name = "FROMCOORDID", nullable = false)
private int fromCoordID;
/**
* To Coordinate_id value
*/
@Column(name = "TOCOORDID", nullable = false)
private int toCoordID;
//private Coordinate toCoordID;
}
HashMap - > CoodinateID协调代码
private void setupCoordinateIDToCoordinate() {
HashMap<Integer, Coordinate> coordinateIDToCoordinate = new HashMap<Integer, Coordinate>();
List<Coordinate> coordinates = coordinateDao.findAll();
Iterator <Coordinate> itr = coordinates.iterator();
Coordinate c;
while(itr.hasNext()) {
c = itr.next();
coordinateIDToCoordinate.put(c.getCoordinateID(),c);
}
}
答案 0 :(得分:1)
看一下在mysql中使用explain命令,让你知道最好放置索引的位置。
以下链接解释得非常好。
http://forums.spry.com/howtos/1345-using-mysqls-explain-command.html
答案 1 :(得分:0)
使用Hibernate实现EhCache帮助我提高了性能