Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何度量hibernate性能?_Hibernate_Jprofiler_Performance - Fatal编程技术网

如何度量hibernate性能?

如何度量hibernate性能?,hibernate,jprofiler,performance,Hibernate,Jprofiler,Performance,如何在hibernate中度量性能?我想知道hibernate执行一个查询需要多少时间?你的意思是字面上的查询还是查询+将数据转换成Java对象 无论哪种方式,如果你想科学化,使用像JProbe这样的分析工具可能是一种选择。您不必花钱,Eclipse中也有一些免费工具 在最简单的情况下,只要在所讨论的代码周围添加一些print语句就足够了,前提是您所测量的内容是主要的处理 要真正彻底地进行性能分析,需要非常小心。通常,您需要多次重复您正在测试的内容,以确保您不会被初始开销(例如打开与数据库的连接

如何在hibernate中度量性能?我想知道hibernate执行一个查询需要多少时间?

你的意思是字面上的查询还是查询+将数据转换成Java对象

无论哪种方式,如果你想科学化,使用像JProbe这样的分析工具可能是一种选择。您不必花钱,Eclipse中也有一些免费工具

在最简单的情况下,只要在所讨论的代码周围添加一些print语句就足够了,前提是您所测量的内容是主要的处理


要真正彻底地进行性能分析,需要非常小心。通常,您需要多次重复您正在测试的内容,以确保您不会被初始开销(例如打开与数据库的连接)误导。不要忘记,数据库和性能可能是至关重要的,hibernate本身无法对调优不好的数据库采取任何措施。

我建议使用以下一种或几种选项:

  • 数据库探查器(e.q.SqlServer探查器)
  • Hibernate的内置统计信息(请参阅:)
  • Hibernate分析器(请参阅:,)

JProfiler 7.1有一个JPA/Hibernate探测器:

下面是一个显示其工作原理的屏幕演示:

热点视图如下所示:


免责声明:当我使用Spring Hibernate进行开发时,我的公司会开发JProfiler 我通常使用以下属性
在my 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)}

谢谢你的回复。你有没有在hibernate中为性能分析提供任何特定的免费工具或eclipse插件?我在谷歌上看到过,我自己从未使用过,但肯定值得一看?