Hibernate和JDBC的性能? [英] Hibernate and JDBC performance?

查看:129
本文介绍了Hibernate和JDBC的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在将我的java web应用程序从JDBC切换到Hibernate,在我当前使用JDBC实现的过程中,我将静态数据加载到应用程序初始化到静态变量中,所以我不必每次都需要直接访问数据库一些静态数据,现在切换到休眠我正在考虑摆脱这些静态变量,因为据我研究Hibernate一直在缓存中加载数据。



我是相当新的休眠,所以我不知道如果从我当前的方法切换到休眠会给任何性能改进。我将进一步研究冬眠缓存并运行一些性能测试,以查看哪种方法更好,但只是对其他人对这两种方法的性能有何看法。



<对于大多数数据库供应商来说,与Hibernate相比,JDBC将始终提供更好的性能。

您可以检查下面链接中提供的比较结果。他的结论是,当查询行数较少的行时,hibernate的速度很快,否则jdbc会更好。



http://phpdao.com/hibernate_vs_jdbc/

另一个很好的表现统计可以在Hiberate论坛讨论 https://forum.hibernate.org/viewtopic.php?f=1&t = 931708



它声明由于使用hibernate而导致的性能下降顺序,请注意,可以通过将hibernate调整为满足需求来改善此问题。

 对象:8  -  Hibernate:10ms / Direct JDBC:10ms =比率:1.0 
对象:16 - Hibernate: 10ms /直接JDBC:0ms =比率:无限
对象:64 - Hibernate:20ms /直接JDBC:10ms =比率:2.0
对象:256 - 休眠:150ms /直接JDBC:30ms =比率:5.0
对象:512 - 休眠:210ms /直接JDBC:40ms =比率:5.25
对象:1024 - Hibernate:410ms /直接JDBC:70ms =比率:5.857143
对象:2048 - 休眠:681ms /直接JDBC:180ms =比率:3.7833333

通过jdbc和sql查询选择hibernate不是因为性能,而是因为主要原因主要是对象持久性和数据库在不写数据库特定查询方面的独立性。您可以阅读pdf指南,以获得更好的视图。



http://www.mindfiresolutions.com/mindfire/Java_Hibernate_JDBC.pdf


Currently i am switching my java web application from JDBC to Hibernate, in my current implementation with JDBC i load up static data on initialization of the application into static variables so i don't have to directly access the database every time i need some static data, now switching to hibernate i am thinking of getting rid of these static variables as as far as i have researched hibernate keeps loaded data in a cache.

I am fairly new to hibernate so i am not sure if switching from my current method to hibernate will give any performance improvements. I am going to research further into hibernates caching and run some performance tests to see which method is better but would just like some opinions on what others think regarding performance on both these methods.

Thanks.

解决方案

JDBC will always give better performance as compared to Hibernate for most of the database vendors. You can check the comparison made as given in the link below. He concludes that hibernate is fast when quering tables with less rows else jdbc is way better.

http://phpdao.com/hibernate_vs_jdbc/

Another good performance stats can be found in Hiberate forum discussion at https://forum.hibernate.org/viewtopic.php?f=1&t=931708

It states the following order of performance hit taken due to use of hibernate, Please note that this can be improved by tuning hibernate to ones needs.

Objects: 8 - Hibernate: 10ms / Direct JDBC: 10ms = Ratio: 1.0 
Objects: 16 - Hibernate: 10ms / Direct JDBC: 0ms = Ratio: Infinity 
Objects: 64 - Hibernate: 20ms / Direct JDBC: 10ms = Ratio: 2.0 
Objects: 256 - Hibernate: 150ms / Direct JDBC: 30ms = Ratio: 5.0 
Objects: 512 - Hibernate: 210ms / Direct JDBC: 40ms = Ratio: 5.25 
Objects: 1024 - Hibernate: 410ms / Direct JDBC: 70ms = Ratio: 5.857143 
Objects: 2048 - Hibernate: 681ms / Direct JDBC: 180ms = Ratio: 3.7833333 

The choice of hibernate over jdbc and sql queries is not because of the performance but because of reasons mainly object persistence and database independence in terms of not writing database specific queries. You can read pdf guide to get a better view.

http://www.mindfiresolutions.com/mindfire/Java_Hibernate_JDBC.pdf

这篇关于Hibernate和JDBC的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆