Annyce Davis

Helping you write beautiful code

  • Home
  • Public Speaking
  • About Me
  • Courses
  • Life

Monitor Hibernate Cache Statistics in Grails Application

March 18, 2010 by Annyce Davis 2 Comments

After going through the effort of adding cache:true all over your application to take advantage of the Hibernate caching you will want to monitor the results. In order to do so you only need to modify two files, DataSource.groovy and a desired Controller.

//In your DataSource.groovy
hibernate {
generate_statistics=true
}

//In your Controller
def sessionFactory

def showCacheStatistics = {
def statistics = sessionFactory.statistics
log.info(statistics)
render statistics
}

Here is the output of calling the showCacheStatistics method on your controller:
Statistics[start time=1269058393252,sessions opened=27,sessions closed=25,transactions=18,successful transactions=3,optimistic lock failures=0,flushes=21,connections obtained=15,statements prepared=219,statements closed=219,second level cache puts=45,second level cache hits=1,second level cache misses=0,entities loaded=40,entities updated=5,entities inserted=48,entities deleted=0,entities fetched=26,collections loaded=20,collections updated=0,collections removed=0,collections recreated=12,collections fetched=18,queries executed to database=93,query cache puts=6,query cache hits=8,query cache misses=6,max query time=89]

Currently I’m showing just a direct rendering of the statistics object, but you could specify which parameters are important to you and only show those, or perhaps send the data to a gsp file and have it formatted in some way.

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Related

Filed Under: Grails Tagged With: Caching, Hibernate Cache

Newsletter

Follow Me

So You Want to Be an Android Developer…

If I had a nickel for every time someone asked me: How do I become an Android Developer? Let's just say I'd have a whole lot of nickels! So as a gift to the … [Read More...]

[NEW COURSE]: “Intermediate Kotlin for Android Developers”

My second course with LinkedIn Learning is now available, "Intermediate Kotlin for Android Developers"! As an avid fan of the Kotlin programming language, I had … [Read More...]

Categories

  • Android (45)
  • Communication (2)
  • Git (3)
  • Gradle (4)
  • Grails (23)
  • Java (8)
  • JavaScript (6)
  • Kotlin (8)
  • Life (2)
  • Public Speaking (20)
  • RxJava (1)
  • Twitter (3)
  • Uncategorized (11)
  • Video Course (3)

Copyright © 2019 · Beautiful Pro Theme on Genesis Framework · WordPress · Log in