【问题标题】:how can I obtain grails hibernate L2 cache statistics?如何获取 grails hibernate L2 缓存统计信息?
【发布时间】:2012-07-22 05:13:52
【问题描述】:

grails hibernate L2 缓存统计 - net.sf.ehcache.Statistics

我将 ehcache 与我的 L2 缓存一起使用。

我想分析性能并从 net.sf.ehcache.Statistics 获取统计信息。 没有任何成功,我一直在寻找一种从 Grails 或 Spring 访问 L2 缓存管理器的方法。

感谢任何提示。

下面是使用的典型休眠设置

hibernate {

    cache.use_second_level_cache = true

    cache.use_query_cache = true

    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'

    format_sql = true

    use_sql_comments = true
}

【问题讨论】:

    标签: hibernate grails profiling ehcache


    【解决方案1】:

    您可以通过将sessionFactory 注入您的服务,然后在其上注入enable statistics 来获取它:

    class My Service {
    
      def sessionFactory
    
      def myMethod() {
        // Enable stats
        Statistics stats = sessionFactory.getStatistics();
        stats.setStatisticsEnabled(true);
    
       // Do some querying and analyse the stats
    
      }
    
    }
    

    【讨论】:

    • 谢谢,我注意到“stats.getSecondLevelCacheRegionNames()”只返回“StandardQueryCache,UpdateTimestampsCache”。我是否正在寻找正确的位置来验证我的 L2 缓存? Bellow 是我的域类映射。 class LogCauseMemento { static mapping = { version false id generator: 'assigned' table 'log_cause' cache: true } } Bellow 是域条目 ehcache.xml。
    • Hibernate 文档在这方面做得很好 (docs.jboss.org/hibernate/orm/3.3/reference/en/html/…)。您可以致电sessionFactory.getStatistics() .getSecondLevelCacheStatistics(regionName) .getEntries();,其中regionName 手杖可以通过致电getSecondLevelCacheRegionNames() 找到
    【解决方案2】:

    只需将generate_statistics=true 添加到您的休眠设置:

    hibernate {
        ...
        generate_statistics=true
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-12
      • 2017-09-24
      • 2011-06-21
      • 2020-11-26
      • 2010-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多