problem in speed while using ehCache

View: New views
4 Messages — Rating Filter:   Alert me  

problem in speed while using ehCache

by Shahapurkar, Suhas P :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello,

Newbie in ehcache!

We have changed the hibernate.cfg.xml like:

 

 

<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>

 

    <property name="hibernate.cache.provider_configuration">/ehcache.xml</property>

    <property name="hibernate.cache.use_minimal_puts">false</property>

    <property name="hibernate.cache.use_query_cache">true</property>

    <property name="hibernate.cache.use_second_level_cache">true</property>

    <property name="hibernate.cache.use_structured_entries">true</property>

 

     <mapping resource="customers.hbm.xml"/>

 

 

HBM File is like:-

 

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"

    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-access="field">

    <class name="staticdata.model.Customer"

           lazy="true" dynamic-update="true"

           table="Customers">

 

        <cache usage="read-write"/>               

          

        <id name="customerID" >

            <generator class="native"/>

        </id>

        <property name="customerShortName" type="string" />

 

                        --------------------------------

                        -------------------------------

 

ehCache file is like:

 

      <cache name="staticdata.model.Customer"

        maxElementsInMemory="2500"

        eternal="false"

        overflowToDisk="false"

        timeToIdleSeconds="300"

        timeToLiveSeconds="0"/>         

</ehcache>

 

While retrieving the record as:

 

            tx = session.beginTransaction();

           

            Criteria criteria = session.createCriteria(Customer.class);

          

criteria.add(Expression.ne(key, column.get(key)));

criteria.add(Expression.eq(key, column.get(key)));

                 

            //criteria.setCacheable(true);

            result = criteria.list();

            tx.commit();

 

It takes approx 4516 ms for just 900 Records. It is faster then the normal retrieval (without ehCache) but still seems to be very slower

 

I am not sure if I am missing some thing

 

Please suggest any possible solutions.

 

Regards,

 

 

 

 

 

 



The information contained in this transmission may contain privileged and confidential information and is intended only for the use of the person(s) named above. If you are not the intended recipient, any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you received this email in error, please contact the sender immediately by reply e-mail and destroy all copies of the original message. This email is not intended as an offer or solicitation for the purchase or sale of any financial instruments.

 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list

Parent Message unknown Re: problem in speed while using ehCache

by gregluck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Suhas

You are on the wrong track there with dynamic-update. See http://www.hibernate.org/hib_docs/reference/en/html/performance.html for an explanation of the terms. 

The simplest thing is, if you do not mind a certain amount of staleness, just use the timeToLive feature.

On a single-JVM use the read-write setting in the hbm file so that writes are made to the cache. 

If changes are being made on other JVMs then use the distributed caching feature of ehcache. If you want to be sure that a change in one place invalidates all caches, then use synchronous replication with invalidation. For higher performance use asynchronous replication with copy of updates.

If the changes are being made outside Java, then it gets harder. You need to do something like create a trigger on a database table, and then pick up the changes to invalidate the caches. You can tie that into ehcache with the CacheExtension interface.


On 14/05/2008, at 9:48 PM, Shahapurkar, Suhas P wrote:

Thanks for all the support.
One last question (I hope so.. J).
 
How can we ensure that the cache is updated/refreshed if data is changed in the database tables?
 
We have actually added this line: -  dynamic-update="true" in the HBM File.
 
Thanks!
 
Regards,
Suhas
 
 

From: Greg Luck [gluck@...] 
Sent: Tuesday, May 13, 2008 12:59 PM
To: Shahapurkar, Suhas P
Subject: Re: [ehcache-list] problem in speed while using ehCache
 
Hi
 
It acts as a pull-through cache effectively. With Hibernate it does not preload. So you first hit is full cost. The second and subsequent hits are cached.
 
 
On 13/05/2008, at 4:03 PM, Shahapurkar, Suhas P wrote:


Thanks for the email.
I have tested with the changes and now it is taking much lesser time (1718ms)
 
One basic question though, when does ehCache caches the data? Loading the ehCache.xml, hibernate.cfg.xml and **.hbm.xml OR after first time retriving the data?
 
Regards,
Suhas
 

From: Greg Luck [gluck@...] 
Sent: Tuesday, May 13, 2008 6:16 AM
To: Shahapurkar, Suhas P
Subject: Re: [ehcache-list] problem in speed while using ehCache
 
Hi
 
Why don't you try setting the timeToLive to a large number like 5000 to make sure it is not expiring while you are using it. Remove the timeToIdle. I don't think you want that.
 
Maybe also try setting lazy to false to make sure the thing is fully loaded.
 
Set the hibernate show sql to true. That way it will show you each time it does database work. If the caching is working you should see database work disappear.
 
Remember the first time you execute the query the work gets done. Then the second time it should use the query cache.
 
You should also use a query cache. To do so do criteria.setCacheable(true) and then specify the cache name you are using with criteria.setCacheRegion("myquerycache"). Create an extra ehcache config for it.
 
This should ramp things up for you.
 
On 12/05/2008, at 6:15 PM, Shahapurkar, Suhas P wrote:



Hello,
Newbie in ehcache!
We have changed the hibernate.cfg.xml like:
 
 
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
 
    <property name="hibernate.cache.provider_configuration">/ehcache.xml</property>
    <property name="hibernate.cache.use_minimal_puts">false</property>
    <property name="hibernate.cache.use_query_cache">true</property>
    <property name="hibernate.cache.use_second_level_cache">true</property>
    <property name="hibernate.cache.use_structured_entries">true</property>
 
     <mapping resource="customers.hbm.xml"/>
 
 
HBM File is like:-
 
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
<hibernate-mapping default-access="field">
    <class name="staticdata.model.Customer"
           lazy="true" dynamic-update="true"
           table="Customers">
 
        <cache usage="read-write"/>               
          
        <id name="customerID" >
            <generator class="native"/>
        </id>
        <property name="customerShortName" type="string" />
 
                        --------------------------------
                        -------------------------------
 
ehCache file is like:
 
      <cache name="staticdata.model.Customer"
        maxElementsInMemory="2500"
        eternal="false"
        overflowToDisk="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="0"/>         
</ehcache>
 
While retrieving the record as:
 
            tx = session.beginTransaction();
           
            Criteria criteria = session.createCriteria(Customerclass);
          
criteria.add(Expression.ne(key, column.get(key)));
criteria.add(Expression.eq(key, column.get(key)));