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.  [ 5 posts ] 
Author Message
 Post subject: second level cache performance EHcache not working
PostPosted: Tue Jun 28, 2005 12:07 pm 
Newbie

Joined: Mon May 16, 2005 11:25 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp


How do I test that my second level cache is working properly?

I have tried enabling the second level cache (ehcache) and wrote a test case to read a table with over 40,000 rows. I have a loop that will spawn one thread after another to read the same data from table over and over, so none of these threads concurrently access the database. I have set the cache to read-only in the mapping file, and I flush, clear, and close the session in between test runs.

When I start my test, it looks like my cache is setup properly because i see these lines at startup:

Code:
Jun-28-2005 11:52:25  INFO (SettingsFactory.java:209) - Second-level cache: enabled
Jun-28-2005 11:52:25  INFO (SettingsFactory.java:213) - Query cache: disabled
Jun-28-2005 11:52:25  INFO (SettingsFactory.java:321) - Cache provider: org.hibernate.cache.EhCacheProvider
Jun-28-2005 11:52:25  INFO (SettingsFactory.java:228) - Optimize cache for minimal puts: disabled
Jun-28-2005 11:52:25  INFO (SettingsFactory.java:233) - Cache region prefix: hibernate.test
Jun-28-2005 11:52:25  INFO (SettingsFactory.java:237) - Structured second-level cache entries: disabled
Jun-28-2005 11:52:26  WARN (Configurator.java:126) - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/hibernate-3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
Jun-28-2005 11:52:26  WARN (CacheFactory.java:43) - read-only cache configured for mutable class: hibernate.test.com.itp.gt.reference.pojos.RefBic
Jun-28-2005 11:52:26  WARN (EhCacheProvider.java:97) - Could not find configuration [hibernate.test.com.itp.gt.reference.pojos.RefBic]; using defaults.
Jun-28-2005 11:52:26  INFO (SessionFactoryObjectFactory.java:82) - Not binding factory to JNDI, no JNDI name configured



When I enable second level cache, the performance does not change (the timings in my test runs are the same when second level cache is disabled). Also, I noticed that there is still network activity after the first run. I'm assuming that after the first run, the data should be in the cache and that threads should not access the database through the network if the data is already in the cache.
Is this correct?

How do I check if my cache is working and how do I view what's in my cache?


Hibernate version:
3.0.5

Mapping documents:
RefBic.hbm.xml


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
        Auto-generated mapping file from
        the hibernate.org cfg2hbm engine
-->
    <class name="com.itp.gt.reference.pojos.RefBic" table="REF_BIC" schema="S">
        <id name="bic" type="string">
            <column name="BIC" length="15" />
            <generator class="assigned" />
        </id>
        <property name="institution" type="string">
            <column name="INSTITUTION" length="120" />
        </property>
        <property name="branch" type="string">
            <column name="BRANCH" length="80" />
        </property>
        <property name="city" type="string">
            <column name="CITY" length="50" />
        </property>
        <property name="country" type="string">
            <column name="COUNTRY" length="50" />
        </property>
        <property name="srcInfo" type="string">
            <column name="SRC_INFO" length="2" />
        </property>
        <property name="updateDate" type="timestamp">
            <column name="UPDATE_DATE" length="7" />
        </property>
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
logger.info(logger.getName() + " loadAllRefBic");

      Transaction myTransaction = null;

      long startTime = System.currentTimeMillis();

      try {
         
         myTransaction = hibernateSession.beginTransaction();

         
         Criteria query = hibernateSession.createCriteria(RefBic.class);

         
         java.util.Iterator results = query.list().iterator();

         RefBic myRefBic;

         
         java.util.LinkedList retrievedArtifacts = new java.util.LinkedList();
         
         while (results.hasNext()) {
            myRefBic = (RefBic) results.next();
            //             logger.info(myRefBic.getInstitution());
            if (!retrievedArtifacts.contains(myRefBic))
               retrievedArtifacts.add(myRefBic);
         }
         
         myTransaction.commit();
         hibernateSession.clear();
      } catch (Exception e) {
         e.printStackTrace();
         try {
            myTransaction.rollback();
         } catch (Exception e2) {
            // Silent failure of transaction rollback
         }
      } finally {
         long duration = System.currentTimeMillis() - startTime;
         logger.info("Timing # : " + duration);
         totalTime += duration;
         logger.info("Total time: " + totalTime);
         try {
            if (hibernateSession != null) {
               hibernateSession.flush();
               hibernateSession.close();
            }
         } catch (Exception e) {
            e.printStackTrace();
            // Silent failure of session close
         }

      }



Full stack trace of any exception that occurs:

Name and version of the database you are using:
oracle 9.2
The generated SQL (show_sql=true):
Jun-28-2005 11:53:36 INFO (?:?) - com.itp.gt.reference.cachetest.CacheTest loadAllRefBic
Hibernate: select this_.BIC as BIC0_, this_.INSTITUTION as INSTITUT2_6_0_, this_.BRANCH as BRANCH6_0_, this_.CITY as CITY6_0_, this_.COUNTRY as COUNTRY6_0_, this_.SRC_INFO as SRC6_6_0_, this_.UPDATE_DATE as UPDATE7_6_0_ from STEVEN.REF_BIC this_

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 12:09 pm 
Newbie

Joined: Mon May 16, 2005 11:25 am
Posts: 8
has anyone successfully written test cases to test the cache performance in hibernate?
any help is appreciated.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 12:31 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
http://www.hibernate.org/hib_docs/v3/re ... querycache


Top
 Profile  
 
 Post subject: second-level caching
PostPosted: Wed Jul 06, 2005 11:50 am 
Newbie

Joined: Tue Jun 07, 2005 10:46 am
Posts: 15
cbx123,
I posted the very same type of question/problem to the list a few weeks back and did not get an answer. The best I could reason was that if you see your cache data files being populated it stands to reason that if hibernate and ehcache are writing to the files then they are reading from the files too. Someone in my office thought that maybe you see a database hit because the query is suppose to be run even with caching, except that the objects are materialized from the cache rather than from the db side. I got tired of getting slammed asking this question. Apparently the answer is so obvious it should be just jumping out at us from the documentation. :)

Good luck.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 12:06 pm 
Newbie

Joined: Mon May 16, 2005 11:25 am
Posts: 8
thanks for the replies.

i actually tried printing out the second level cache statistics and verified the number of cache hits and misses.
so now i know it's working, although my performance has not increased from the cache.


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

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.