This page describes usage of Hibernate Smoke Detector, a simple parser that counts queries executed in each second and generates a report showing places where might be some problems, eg. n+1 problem or non optimal number of counts on page testing visibility of many elements. Parser can be also useed for JPA queries.
More details: http://tomaszdziurko.pl/2012/07/hibernate-smoke-detector/
Hibernate Smoke Detector is simple but quite useful parser that checks your application and helps to eliminate identical queries fired many times in a very short period of time.
It generates a report showing two things:
- which queries are executed most times and when so developer could find them in his code easily.
- which tables are used two times in join/where clause.
- N+1 problems
- duplicated queries checking condition on the same page/view.
- redundant tables used more than once in join/where section
- Set up logger in your application to write all hql queries to a separate file
- Run your end-to-end tests (in our case Selenium tests) or just let testers do some clicking through your application
- Get sources from https://github.com/tdziurko/hibernate-smoke-detector
- mvn clean install
- Run Hibernate Smoke Detector with your log file: java -jar hibernate-smoke-detector/target/hibernate-smoke-detector-1.0-jar-with-dependencies.jar [your_log_file] > [your_report_file]
- Analyze the report and fix problems.
Below some example settings for JBoss and Logback:
pattern="%d{HH:mm:ss,SSS} %-5p [%c] %s%E%n" // for JBoss Logger
%date{"HH:mm:ss,SSS"} %-5p [%c] %message%ex%n // for Logback
This part of log is indispensable so parser could put each query to the proper "date-time basket", so if you want to use if out of the box, you should setup your logger accordingly. If you can not change date format in hql log file, you have to fork the project and modify source code a little bit.
- Author: Tomasz Dziurko
- Source code: https://github.com/tdziurko/hibernate-smoke-detector/
- Blog post describing this mini-project in more detail: http://tomaszdziurko.pl/2012/07/hibernate-smoke-detector/