[英]Why Hibernate slows down after while?
在執行相同的查詢(只讀)后,休眠速度變慢的原因可能是什么?
日志:
368588 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
158339 nanoseconds spent preparing 3 JDBC statements;
33855736 nanoseconds spent executing 3 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);
9437 nanoseconds spent executing 3 partial-flushes (flushing a total of 0 entities and 0 collections)
}
2020-03-24 09:02:54.488 INFO 12024 --- [io-8064-exec-10] i.StatisticalLoggingSessionEventListener : Session Metrics {
44640 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
134337 nanoseconds spent preparing 3 JDBC statements;
33256438 nanoseconds spent executing 3 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);
9156 nanoseconds spent executing 3 partial-flushes (flushing a total of 0 entities and 0 collections)
}
2020-03-24 09:02:56.143 INFO 12024 --- [nio-8064-exec-1] i.StatisticalLoggingSessionEventListener : Session Metrics {
47060 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
123461 nanoseconds spent preparing 3 JDBC statements;
468759882 nanoseconds spent executing 3 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);
9680 nanoseconds spent executing 3 partial-flushes (flushing a total of 0 entities and 0 collections)
}
從日志中可以看出,執行時間增加了十倍
可以配置 Hibernate c3p0 以提高效率。 連接池對性能有好處,因為它可以防止 Java 應用程序每次與數據庫交互時都創建連接,並最大限度地減少打開和關閉連接的成本。
嘗試使用此鏈接在您的應用程序中配置休眠 c3p0:
https://mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.