我有一個在 DBeaver 中運行大約 6ms 的查詢,我使用通用日志來提取正在傳遞的查詢,該查詢與我的 Tomcat 服務器連接到的資料庫相同
select min(organizati0_.Downloaded) as col_0_0_ from oss_collection_history organizati0_
where organizati0_.AccountingSystem='SomeSystem'
and (organizati0_.Org in ('ID1' , 'ID2', ..., 'ID10' ))
在針對資料庫的 Dockerized 副本運行 Spring Data JPA 的 JUnit 測驗中,查詢的運行速度也非常快,為 60 毫秒,但在 Tomcat 上需要 8-10 秒以上。
所以不完全確定發生了什么。
我這樣做只是為了使用相同的引數來分析函式呼叫。
var start = System.currentTimeMillis();
consolidatedDownloadSvc.getAvailableYearsOfDownloadedForAccountingSystem(...);
System.out.println(System.currentTimeMillis() - start);
它不會出現在慢日志中,即使我set global log_queries_not_using_indexes = 'ON';這樣會向我表明該查詢已編入索引。
所以我想知道是否有某種日志可以顯示我在 Spring-Data 和 Hibernate 中可能缺少的任何額外內容。
uj5u.com熱心網友回復:
除了@Panagiotis 建議的內容外,啟用以下統計資訊也有助于了解休眠狀態在哪個階段花費更多時間。
spring.jpa.properties.hibernate.generate_statistics=true
logging.level.org.hibernate.stat=DEBUG
您會在日志中看到類似下面的內容
2021-12-29 10:54:52.408 INFO 31972 - – [ main] i.StatisticalLoggingSessionEventListener : Session Metrics {
5070899 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
4359903 nanoseconds spent preparing 20 JDBC statements;
76117198 nanoseconds spent executing 20 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
132026893 nanoseconds spent performing 40 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
838900 nanoseconds spent performing 19 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
16900 nanoseconds spent executing 1 partial-flushes (flushing a total of 0 entities and 0 collections)
}
uj5u.com熱心網友回復:
您可以在application.properties檔案中使用以下屬性集。如果您沒有特定的記錄器策略,它們將被推送到您的 tomcatcatalina.log檔案
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.type=trace
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/396749.html
上一篇:你如何處理物件的異步初始化?
下一篇:Kotlin接收器名稱沖突
