These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]

Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate and Ehcache Distributed Caching Question
PostPosted: Wed Aug 08, 2007 9:53 pm 

Joined: Wed Aug 08, 2007 7:40 pm
Posts: 2
So, I have a question in relation to Hibernate and ehcache, specifically setting up distributed caching and observing it in action.

I'm working in a setup that uses Hibernate 3.2 (3.2.5, I think), which has ehcache 1.2.3 included. We use ehcache for our second-level caching. I have been tasked with setting up distributed caching.

Here is what the ehcache.xml file looked like before I started working on it (all other parts of the file were comments):


Our Hibernate.cfg.xml was as follows:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"


      <mapping class="com.model3.resource.image.Image"/>
      <mapping class="com.model3.resource.document.Document"/>
      <mapping class="com.model3.resource.stylesheet.Stylesheet"/>
        <mapping class="com.model3.admin.client.Client"/>
        <mapping class="com.model3.admin.user.User"/>
        <mapping class="com.model3.admin.user.Role"/>
      <mapping class="com.model3.admin.motd.Motd"/>
      <mapping class="com.model3.admin.timezone.Timezone"/>
      <mapping class="com.model3.auth.ReauthInfo"/>
        <mapping class="com.model3.creation.application.Application"/>
        <mapping class="com.model3.creation.module.Module"/>
        <mapping class="com.model3.creation.page.Page"/>
        <mapping class="com.model3.creation.page.Paragraph"/>
        <mapping class="com.model3.creation.page.Note"/>
        <mapping class="com.model3.value.definition.DataElement"/>
        <mapping class="com.model3.value.definition.DataElementDefaultValue"/>
        <mapping class="com.model3.value.definition.DataElementChoiceValue"/>
        <mapping class="com.model3.value.scalar.BaseScalarValue"/>
        <mapping class="com.model3.value.scalar.ImageValue"/>
        <mapping class="com.model3.value.scalar.DocumentValue"/>
        <mapping class="com.model3.value.scalar.StringValue"/>
        <mapping class="com.model3.value.scalar.ChoiceValue"/>
        <mapping class="com.model3.value.scalar.DoubleValue"/>
        <mapping class="com.model3.value.scalar.BooleanValue"/>
      <mapping class="com.model3.value.scalar.JulianDayValue"/>
      <mapping class="com.model3.resource.document.Document"/>
      <mapping class="com.model3.resource.theme.Theme"/>
      <mapping class="com.model3.resource.image.ImageResource"/>
      <mapping class="com.model3.resource.stylesheet.Stylesheet"/>
      <mapping class="com.model3.resource.stylesheet.StylesheetResource"/>
      <mapping class="com.model3.resource.textcomponent.TextComponent"/>
      <mapping class="com.model3.resource.textcomponent.TextComponentResource"/>
      <mapping class="com.model3.history.user.UserLocation"/>


We use Tomcat to run the app. Upon Tomcat startup, it initialized all of the caches like so (with a line like this for each mapping entry in the Hibernate config):

org.hibernate.cache.EhCacheProvider buildCache
Warning: Could not find configuration [com.model3.resource.image.Image]; using defaults.

This makes sense to me - since there's no explicit definition for each of those caches in the ehcache.xml file, it just grabs the default settings for all of them.

Now, I wanted to set up the ehcache.xml file for distributed caching, which I did using the ehcache documentation. The new file (extra comments not shown) looks like so:


        <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>

Pretty basic setup, but right now I'm just trying to prove to myself that it can work. Now, I tried starting this up, and Tomcat started up the same as before, with all of the various warning messages telling me buildCache was using the default settings. So far so good. Still needed to figure out whether it was actually working, though.

I acquired the ehcache remote debugger (ehcache-1.2.3-remote-debugger.jar) and attempted to run it on one of these caches to see if it was indeed working (could I see heartbeat packets, were values being replicated, etc). I called this with one of the cache names, using the format the documentation said to use:

java -jar ehcache-1.2.3-remote-debugger.jar \web\WEB-INF\classes\ehcache.xml com.model3.creation.page.Paragraph

I got the following error:

SEVERE: No cache named com.model3.creation.page.Paragraph exists. Available caches:

Well, okay, I figure I screwed up on the naming stuff. Except that's really what it should be called. I went back and added the following to the ehcache.xml file:

<cache name="com.model3.creation.page.Paragraph"

Sure enough, when I started up Tomcat again, I did not get a warning message telling me it was using default values for 'com.model3.creation.page.Paragraph', so obviously it was using the settings in the ehcache.xml file. When I tried using the remote debugger again - with the exact same call as last time - it found the cache successfully and started looking at it. Unfortunately, the only info it ever gave me was 'Cache size = 0'. Which should really not be the case, with that particular cache.

I figured something was going screwy here, and since I couldn't get the remote debugger to work correctly (or I was just being an idiot, a distinct possibility since I've never worked with any of this stuff before), I needed another way to figure out what was going on with the caches. I did that through Hibernate and JConsole - specifically, the Hibernate statistics MBean. I started up JConsole, went to MBeans, and looked at the Statistics entry, specifically at the Second Level Cache entries.

On startup of the application, before I even log myself in, it gave me:

SecondLevelCacheHitCount: 0
SecondLevelCacheMissCount: 58
SecondLevelCachePutCount: 62
SecondLevelCacheReadingNames: Expanded to show a value for every entry in the mapping table (such as com.model3.creation.page.Paragraph).

Upon login, it increased all of the above numbers, obviously (depends what page I click on after I log in, so the specific numbers aren't really important). So, clearly, the cache is there and working, I just can't talk to it with the remote debugger (or don't know how).

Now, as I said, I'm trying to set this up as distributed caching, so I have two machines running with these exact same settings. When I clicked around in one of them, increasing all of the various SecondLevelCache stats in JConsole, those values did not change for the second instance - it remained with the stats you see above. My guess is that this means the caches are not distributing correctly - since new Puts should be distributed to other caches in the cluster, I would expect to see the SecondLevelCachePutCount stat change in the second instance even if I'm only running around doing stuff in the first one. I'm not entirely sure of this, though.

Basically, my questions are as follows:

Am I right - does the stuff I'm seeing in the JConsole mean that the cache is not distributing correctly?

Is there anything I can do to get a better look at what's going on in the cache while the application is running?

Alternatively, does anyone know how to get the ehcache remote debugger talking to the Hibernate second level cache? I realize this isn't the ehcache forum (which is pretty dead as far as I can tell, thus why this forum is my first place to ask), but since it's part of the Hibernate bundle I figure someone might know.

Is there anything I am doing horribly, obviously wrong in my attempt to set up distributed caching?

As I said, this is my first time working with just about any of this stuff. I think I've done a pretty thorough job trying to look around and research possible solutions myself (and, obviously, failing), and I will continue to search and experiment on my own. However, if I missed something obvious, please do feel free to tell me to RTFM (preferably with a link) so that I can prevent such idiocy in the future.

Thanks in advance. This has me pretty frustrated.

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.