Issue
I've recently integrated hibernate into my webapp and am trying to see the performance impact/frequency of db calls that are happening.
After enabling show_sql
and generate_statistics
, when I run the application I see the sql queries run by hibernate and also hibernate statistics. Eg:
08:04:53.724 [http-apr-8080-exec-1] INFO o.h.e.i.StatisticalLoggingSessionEventListener - Session Metrics {
85648 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
0 nanoseconds spent preparing 0 JDBC statements;
0 nanoseconds spent executing 0 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)
}
However the statistics statement gets printed multiple times per api call while the query statements are much lower in number. Also, its very rare to see a non zero value for any other metric except acquiring 1 JDBC connections
in Statistics logs.
So when exactly does the logger run and what am I doing wrong to get so many metric logs?
Thanks
Solution
When you enable hibernate statistics you get session statistics information every time a session is closed. if you dont want this behavior you can disable it with adding of following entry in your log4j file:
log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=OFF
Answered By - Abass A
Answer Checked By - Marie Seifert (JavaFixing Admin)