• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Not a Bug
  • ehcache-core
  • drb
  • Reporter: pb00067
  • September 08, 2011
  • 0
  • Watchers: 1
  • July 27, 2012
  • September 09, 2011

Attachments

Description

While EHCache2.0.0 properly increments the cache-hits counter shown in the CacheStatistics MBean with EHCache2.4.3 & EHCache2.4.4 all hit-counters seems always remain at 0 value, this although Hibernate clearly postulates cache hits in the Hibernate-Statistics MBean, please see attached screenshots. N.B.: It is indeed not relevant if the version of Hibernate is 3.6 or 4.0 so it clearly seems to be a problem of ehcache-core

Comments

Alexander Snaps 2011-09-08

Are you sure the hibernate statistics are enabled ? Either programmatically : Statistics stats = sessionFactory.getStatistics(); stats.setStatisticsEnabled(true); Or through config hibernate.generate_statistics ?

Guenther Demetz 2011-09-09

Yes, I’m setting it through config parameter

and I’m also sure that this setting is properly parsed by hibernate, screenshot ehcache2_4_3_hibernate4hit.png proves it.

Following code I use to register the Ehcache MBean:

_sfi = (SessionFactoryImpl) _entityManagerFactory.getSessionFactory();

// REGISTER MBEANS MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

// Expose Hibernate Statistics as MBean too, if statistics generation is enabled in configuration

if (_sfi.getStatistics().isStatisticsEnabled()) {
                StatisticsService statsMBean = new StatisticsService();
                statsMBean.setSessionFactory(_sfi);
                //statsMBean.setStatisticsEnabled(true); already true 
                 
                ObjectName on = new ObjectName("Hibernate:type=statistics,application=HibernateTravelPOJO");
                if (!mBeanServer.isRegistered(on)) {
                    mBeanServer.registerMBean(statsMBean, on);
                }
                
                if (_sfi.getSettings().isSecondLevelCacheEnabled()) {
                    
                    net.sf.ehcache.CacheManager manager = net.sf.ehcache.CacheManager.create(); // this method supports/attaches singleton cache
                    net.sf.ehcache.management.ManagementService.registerMBeans(manager, mBeanServer, true, true, true, true);
                    
                }
   }

N.B.: I use the EhCache in Singleton mode.

Guenther Demetz 2011-09-09

Hi Alex,

I found the reason for this behavior in class CacheConfiguration:

In EHCache2.0.0 the statistics are enabled by default:

private volatile boolean statistics = true;

whilst in EHCache2.4.3 the statistics are disabled by default:

public static final boolean DEFAULT_STATISTICS = false; private volatile boolean statistics = DEFAULT_STATISTICS;

If I explicitly define statistics=”true” in the ehcache.xml config file

<cache name=”Eternal” … statistics=”true” />

everything turns working as before :-)

Guenther Demetz 2011-09-09

Finally I think it is good that statistics are disabled by default. Just it has to be mentioned somewhere in the documentation, so this issue can be closed :-)

Guenther Demetz 2011-09-09

Oh, I just saw now that this behavior change is in fact already documented. From chapter 27.1.10 Performance

“From Ehcache 2.1.0 statistics are off by default.”

Please close this issue thx G.D.

Alexander Snaps 2011-09-09

Works as expected. Statistics need to be turned on explicitly