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>