hibernate之generate_statistics

这是hibernate提供的一个调优功能,在spring配置文件中加入下面的配置:

  1. spring:
  2. properties:
  3. hibernate:
  4. format_sql: true
  5. generate_statistics: true

就可以打印每个阶段的执行时间

i.StatisticalLoggingSessionEventListener : Session Metrics {
1747799 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
16084554 nanoseconds spent preparing 7 JDBC statements;
7851937 nanoseconds spent executing 7 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)

从上面可以看出上面涉及到7条sql语句,获取jdbc连接耗时1747799纳秒,预准备阶段耗时16084554纳秒,执行阶段7851937纳秒

以及缓存命中情况,当发现sql执行过慢时,可以通过generate_statistics这个功能发现问题

PS:

上面不是一条sql的执行情况,而是一个任务执行涉及到的所有有效sql,比如下面这种

T findById(String id){

sql1;

sql2;

sql3;

}

上面的一次完整查询(一个Session)总共涉及到3条sql

发表评论

表情:
评论列表 (有 0 条评论,14人围观)

还没有评论,来说两句吧...

相关阅读