Performance ObjectDB的JPA查询性能问题
ObjectDB中的查询性能有很大问题,这是我们的代码。任何帮助都将不胜感激 对于数据库中的前40条记录,查询的第一个版本给出的结果为50ms,而查询40+条记录的第二个版本给出的结果为19秒。我们指出,从他的53项记录来看,表现明显下降。在其他查询中,由于结果的大小(可能与相关对象的数量有关),阈值可能不同 代码的第一个版本。 实体管理器工厂emf= Persistence.createEntityManagerFactory(“objectdb://10.10.10.14/E_POLICIJA.odb;用户=管理员;密码=管理员”)//$非NLS-1$Performance ObjectDB的JPA查询性能问题,performance,jpa,objectdb,Performance,Jpa,Objectdb,ObjectDB中的查询性能有很大问题,这是我们的代码。任何帮助都将不胜感激 对于数据库中的前40条记录,查询的第一个版本给出的结果为50ms,而查询40+条记录的第二个版本给出的结果为19秒。我们指出,从他的53项记录来看,表现明显下降。在其他查询中,由于结果的大小(可能与相关对象的数量有关),阈值可能不同 代码的第一个版本。 实体管理器工厂emf= Persistence.createEntityManagerFactory(“objectdb://10.10.10.14/E_POLICIJ
em = emf.createEntityManager();
long startTime;
long endTime;
startTime = System.currentTimeMillis();
int i = 0;
while(i < 40){
TypedQuery<AktImpl> queryAkt =
em.createQuery("SELECT e FROM AktImpl e", AktImpl.class);
queryAkt.setFirstResult(i);
queryAkt.setMaxResults(20);
queryAkt.getResultList();
i += 20;
}
endTime = System.currentTimeMillis();
System.out.println((endTime - startTime));
}
em=emf.createEntityManager();
长启动时间;
长时间;
startTime=System.currentTimeMillis();
int i=0;
而(i<40){
类型查询查询=
em.createQuery(“从AktImpl e中选择e”,AktImpl.class);
queryAkt.setFirstResult(i);
queryAkt.setMaxResults(20);
getResultList();
i+=20;
}
endTime=System.currentTimeMillis();
System.out.println((endTime-startTime));
}
第二版代码
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("objectdb://10.10.10.14/E_POLICIJA.odb;user=admin;password=admin"); //$NON-NLS-1$
em = emf.createEntityManager();
long startTime;
long endTime;
startTime = System.currentTimeMillis();
int i = 0;
while(i < 60){
TypedQuery<AktImpl> queryAkt =
em.createQuery("SELECT e FROM AktImpl e", AktImpl.class);
queryAkt.setFirstResult(i);
queryAkt.setMaxResults(20);
queryAkt.getResultList();
i += 20;
}
endTime = System.currentTimeMillis();
System.out.println((endTime - startTime));
}
EntityManager工厂emf=
Persistence.createEntityManagerFactory(“objectdb://10.10.10.14/E_POLICIJA.odb;用户=管理员;密码=管理员”)//$非NLS-1$
em=emf.createEntityManager();
长启动时间;
长时间;
startTime=System.currentTimeMillis();
int i=0;
而(i<60){
类型查询查询=
em.createQuery(“从AktImpl e中选择e”,AktImpl.class);
queryAkt.setFirstResult(i);
queryAkt.setMaxResults(20);
getResultList();
i+=20;
}
endTime=System.currentTimeMillis();
System.out.println((endTime-startTime));
}
感谢您的帮助我们发现问题是一个循环的急切关系,它在特定的应用程序中定义,需要使用查询结果递归加载许多对象 解决方案是将关系设置从渴望更改为懒惰
更多详细信息请参见。实际上延迟加载并没有解决问题,目前我们已将双向关系改为单向关系,并实现了附加查询。结论是ObjectDB不是问题的根源。双向关系应该以某种标准方式更好地实现。