如何衡量休眠性能?

时间:2010-05-03 05:22:26

标签: hibernate jprofiler performance

如何衡量hibernate的性能?我想知道hibernate执行查询需要多长时间?

4 个答案:

答案 0 :(得分:8)

JProfiler 7.1有一个JPA / Hibernate探针:

http://www.ej-technologies.com/products/jprofiler/whatsnew71.html

这是一个屏幕演示,展示了它的工作原理:

http://blog.ej-technologies.com/2012/01/profiling-jpahibernate.html

热点视图如下所示:

enter image description here

免责声明:我公司开发JProfiler

答案 1 :(得分:5)

我会推荐以下一个或几个选项:

答案 2 :(得分:1)

你的意思是字面上的查询或查询+将数据混合到Java对象中吗?

无论哪种方式,如果你想要科学,使用像JProbe这样的分析工具可能是要走的路。你并不需要花钱,Eclipse中也有一些免费的工具。

在最简单的情况下,如果您正在测量的东西是占主导地位的处理,只需在相关代码周围添加一些打印语句就足够了。

在性能分析中获得非常彻底的考虑非常谨慎。通常你需要运行你正在测试的东西的许多重复,以确保你不会被初始开销误导(例如打开与Db的连接)。并且不要忘记数据库和性能可能很关键,hibernate本身无法对一个调整不佳的数据库做任何事情。

答案 3 :(得分:0)

当我使用Spring Hibernate进行开发时 我通常使用以下属性
在我的application.properties文件中查看 查询执行时间以及查询执行方式:

spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.generate_statistics=true

示例日志输出如下所示:

Hibernate: 
select
    order0_.OrderID as OrderID1_4_0_,
    order0_.customerID as customer2_4_0_,
    order0_.employeeID as employee3_4_0_,
    order0_.freight as freight4_4_0_,
    order0_.orderDate as orderDat5_4_0_,
    order0_.requiredDate as required6_4_0_,
    order0_.shipAddress as shipAddr7_4_0_,
    order0_.shipCity as shipCity8_4_0_,
    order0_.shipCountry as shipCoun9_4_0_,
    order0_.shipName as shipNam10_4_0_,
    order0_.shipPostalCode as shipPos11_4_0_,
    order0_.shipRegion as shipReg12_4_0_,
    order0_.shipVia as shipVia13_4_0_,
    order0_.shippedDate as shipped14_4_0_,
    customer1_.customerID as customer1_2_1_,
    customer1_.address as address2_2_1_,
    customer1_.city as city3_2_1_,
    customer1_.companyName as companyN4_2_1_,
    customer1_.contactName as contactN5_2_1_,
    customer1_.contactTitle as contactT6_2_1_,
    customer1_.country as country7_2_1_,
    customer1_.fax as fax8_2_1_,
    customer1_.phone as phone9_2_1_,
    customer1_.postalCode as postalC10_2_1_,
    customer1_.region as region11_2_1_ 
from
    orders order0_ 
left outer join
    customers customer1_ 
        on order0_.customerID=customer1_.customerID 
where
    order0_.OrderID=?
Hibernate: 
select
    orderdetai0_.OrderID as OrderID6_3_0_,
    orderdetai0_.ID as ID1_3_0_,
    orderdetai0_.ID as ID1_3_1_,
    orderdetai0_.discount as discount2_3_1_,
    orderdetai0_.OrderID as OrderID6_3_1_,
    orderdetai0_.productID as productI3_3_1_,
    orderdetai0_.quantity as quantity4_3_1_,
    orderdetai0_.unitPrice as unitPric5_3_1_ 
from
    order_details orderdetai0_ 
where
    orderdetai0_.OrderID=?

Session Metrics {
281879 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
276015 nanoseconds spent preparing 2 JDBC statements;
1702274 nanoseconds spent executing 2 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)}