5 Replies Latest reply on Nov 27, 2009 11:14 AM by galder.zamarreno

    Examining contents of a single node's Hibernate second level

      Hi -- I'm using Infinispan as my Hibernate second-level cache and am trying to run some diagnostics so I can tune my eviction settings. I saw the other posts about the difficulty of querying the contents of an entire cluster's Infinispan cache -- the questions below are aimed only at Infinispan as a Hibernate second level cache, not at a generalized Infinispan cluster, and are only intended for diagnostics.

      Is calling SessionFactory.getStatistics().getSecondLevelCacheStatistics(region) the best way to examine the contents of an Infinispan-based Hibernate second-level cache, or is there a better way? The reasons I ask are:

      * The resulting stats object contains an instance of org.hibernate.cache.infinispan.entity.EntityRegionImpl, which in turn contains an org.infinispan.CacheDelegate. However, calling stats.getEntries() returns a hashmap that contains the same objects as the CacheDelegate. It looks like getEntries() is copying CacheDelegate's map to a HashMap, and I'm also not able to call any of the methods of the CacheDelegate. Is there a way for me to get directly at the CacheDelete object from my Hibernate code?
      * Is there a way to get the age of an entity in the cache and the last hit time? Hibernate's SecondLevelCacheStatistics doesn't have this info -- is this information available thru the Infinispan/Hibernate cache provider?

      Thanks.

        • 1. Re: Examining contents of a single node's Hibernate second l
          galder.zamarreno

          Hmmm, if what you're after is a cache entries age, as in the time that has passed since the entry was created, and last accessed time, Infinispan does not even make such information public. You might be able to hack to get this information but I wouldn't recommend doing that since it will tie you to the internals of Infinispan.

          IMO, we should enable to query such information via JMX and then you could query it that way. This guarantees that the information is not only available to your use case, but any other one out there and you can access it in a standard way, without hacking it. I'll look into this possibility.

          At the Hibernate level, I think it'd be good for Hibernate to expose this type of information via Statistics but I can't see it happening any time soon. I'll definitely pass the feedback on.

          • 2. Re: Examining contents of a single node's Hibernate second l
            galder.zamarreno

            Actually, providing the JMX hooks in Infinispan to query a cache entry's age or last used time might not be enough in this case because to query Hibernate cache's, you'd have to build the corresponding CacheKey instances that Hibernate uses as wrappers for the cache keys and this is an internal implementation detail of Hibernate.

            • 3. Re: Examining contents of a single node's Hibernate second l
              galder.zamarreno

              Brian, I'm trying to think of a way forward here but I had a question for you. I suppose what you really care about is getting a collection view that shows you the ids of all entities/collections and it's corresponding age, last usage time...etc.

              I suppose that from an eviction planning perspective, this is more useful than you being able to provide an id or primary key and in return get the age and last used time of that particular entity/collection.

              Am I right?

              • 4. Re: Examining contents of a single node's Hibernate second l

                Exactly -- what I was looking for was a way to see a collection of everything in the local cache along with its age and last use. Thanks again,
                Brian

                • 5. Re: Examining contents of a single node's Hibernate second l
                  galder.zamarreno

                  Brian, currently the most suited information to guide you tweaking your eviction policies can be found via:
                  - Hits (Number of cache attribute hits),
                  - Misses(Number of cache attribute misses) ,
                  - HitRatio(Percentage hit/(hit+miss) ratio for the cache)
                  - Evictions (Number of cache eviction operations).

                  To get access to those you need to either modify the Infinispan configuration file or provide a new one where you enable global JMX statistics by adding this element under element:

                  <globalJmxStatistics enabled="true" jmxDomain="infinispan"/>


                  And also cache level JMX statistics by adding the following element under each cache type that you wanna be monitoring:
                  <jmxStatistics enabled="true"/>


                  Once you have enabled these elements, you can use JConsole, JVisualVM or even Jopr to monitor these values in each of the cache instances. Remember to give it a -Dcom.sun.management.jmxremote.port at start time.

                  For the time being, the information that you request is considered internal and hence we won't provide a public view of it.