-->
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: Cache optimization
PostPosted: Fri Mar 06, 2009 7:02 am 
Newbie

Joined: Wed Mar 04, 2009 1:41 pm
Posts: 3
Hi,

I've just started using hibernate and I'm having some problems getting it going fast enough for my needs. For most of what I'm doing it's fine - the usual persistence of settings and user state etc, but one part of the system analyses large sets of time series data and it needs to be (very) fast.

The core classes I have are:

Code:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table( name="TimeSeriesData" )
public class TimeSeriesData implements Serializable {
   @Id private TimeSeriesDataKey key;
   private boolean locked;
   @Column( columnDefinition="varbinary( max )" ) private double[] timeSeriesData;

/*Getters and setters Removed for clarity*/
}

@Embeddable
public class TimeSeriesDataKey implements Serializable {
   private int itemKey;
   private int locationKey;
   private int typeKey;

/*Getters and setters Removed for clarity*/
}


Without the second level cache I can get about 200 TimeSeriesData objects per second. With the second level cache (ehcache) turned on I can up that to about 700 a second. I need at least 10,000 a second so I wrote a very quick and dirty cache (just a HashMap) and was able to achieve 500,000 a second easily.

I'm getting objects like this:
Code:
public TimeSeriesData get( TimeSeriesDataKey key ) {
   EntityManager em = emf.createEntityManager();
   TimeSeriesData data = em.find( TimeSeriesData.class, key );
   return data;
}


My question is this: why is there such a disparity between my trivial cache and ehcache? I expected ehcache to be slower but not that much slower, I thought it would give me 10,000 objects a second easily. Ideally I want a read/write cache (it's read only at the moment to try to extract more speed) so ehcache would be a real benefit over trying to write my own.

My ehconfig file:

Code:
<ehcache xsi:noNamespaceSchemaLocation="ehcache.xsd">

   <cacheManagerEventListenerFactory class="" properties=""/>

   <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>

   <defaultCache maxElementsInMemory="10000"
      eternal="false"
      timeToIdleSeconds="120"
      timeToLiveSeconds="120"
      overflowToDisk="true"
      diskPersistent="false"
      diskExpiryThreadIntervalSeconds="120"
      memoryStoreEvictionPolicy="LRU"
   />

   <cache name="com.example.data.TimeSeriesData"
      maxElementsInMemory="1000000"
      eternal="false"
      timeToIdleSeconds="43200"
      timeToLiveSeconds="86400"
      overflowToDisk="false"
   />

</ehcache>


Top
 Profile  
 
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.