Skip to content

tdziurko/hibernate-smoke-detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

What is it ?

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

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.
Using this mini-application should help you to avoid some problems with your queries that often go to the production unnoticed:
  • N+1 problems
  • duplicated queries checking condition on the same page/view.
  • redundant tables used more than once in join/where section

How it works

  • 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.
Hibernate Smoke Detector counts how many each query was executed in each second, then compiles report starting from queries that have the highest counter. Currently the only drawback is that parser works only with specific date time format in the logs 14:10:44,714 DEBUG [org.hibernate.SQL] select ...

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages