本文介绍了ORM解决方案(JPA; Hibernate)与JDBC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须能够以每5秒至少8000个对象的一致速率插入/更新对象。在Spring / Hibernate / JPA和纯JDBC之间做了一些比较性能测试。我发现使用HSQL的性能有显着的不同。使用Spring / Hib / JPA,我可以在5秒内插入我的1.5 KB对象中的3000-4000个(具有一对多和多对多关系),而使用直接JDBC调用我可以插入10,000-12,000个相同的对象。



我无法弄清楚为什么会有这么大的差异。我已经调整了Spring / Hib / JPA设置,试图在性能上接近失败。我希望将Spring / Hib / JPA用于未来目的,可扩展性以及因为外键关系(一对多和多对多)难以手工维护;但性能要求似乎指向使用纯JDBC。



关于为什么会存在如此巨大的差异的任何想法?

解决方案

在批处理模式下,我们有类似的经验比较Hibernate和JDBC(Statement#executeBatch())。基本上,Hibernate似乎对批量操作没有那么好。在我们的例子中,Hibernate的实现在我们的生产硬件上足够快。

您可能想要做的是将数据库调用包装在DAO中,让您的应用程序一种访问数据的一致方式。在使用Hibernate的地方方便实现DAO,并在性能要求要求的情况下使用JDBC。


I need to be able to insert/update objects at a consistent rate of at least 8000 objects every 5 seconds in an in-memory HSQL database.

I have done some comparison performance testing between Spring/Hibernate/JPA and pure JDBC. I have found a significant difference in performance using HSQL.. With Spring/Hib/JPA, I can insert 3000-4000 of my 1.5 KB objects (with a One-Many and a Many-Many relationship) in 5 seconds, while with direct JDBC calls I can insert 10,000-12,000 of those same objects.

I cannot figure out why there is such a huge discrepancy. I have tweaked the Spring/Hib/JPA settings a lot trying to get close in performance without luck. I want to use Spring/Hib/JPA for future purposes, expandability, and because the foreign key relationships (one-many and many-many) are difficult to maintain by hand; but the performance requirements seem to point towards using pure JDBC.

Any ideas of why there would be such a huge discrepancy?

解决方案

We have similar experience comparing Hibernate with JDBC in batch mode (Statement#executeBatch()). Basically, it seems like Hibernate just doesn't do that well with bulk operations. In our case, the Hibernate implementation was fast enough on our production hardware.

What you may want to do, is to wrap your database calls in a DAO, giving your application a consistent way of accessing your data. Implement your DAOs with Hibernate where it's convenient, and with JDBC where the performance requirements call for it.

这篇关于ORM解决方案(JPA; Hibernate)与JDBC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:05