-->
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.  [ 6 posts ] 
Author Message
 Post subject: Second level cache performace.
PostPosted: Fri Oct 22, 2004 4:38 am 
Newbie

Joined: Thu Oct 21, 2004 11:58 am
Posts: 3
Hibernate version: 2.1
Hi,
I am using second level cache with ehcache provider. It seems between 3 or 4 times slower than first level cache. Maybe i am doing something wrong. What can i do to optimize second level cache?
Thanks.

Mapping documents:
This is my class:
Code:
<class name="VerticeHB" table="VERTICE" mutable="false" >
  <cache usage="read-only"/>     
    <id name="id" column="id" type="long">
      <generator class="sequence">
        <param name="sequence">mls.vertice_seq</param>
      </generator>
    </id>
    <set name="arista" lazy="true" inverse="true" >
      <cache usage="read-only"/>
      <key column="id_parent"/>
      <one-to-many class="AristaHB"/>
    </set>
</class>

And ehcache.xml:
Code:
<ehcache>
  <diskStore path="java.io.tmpdir"/>
  <defaultCache maxElementsInMemory="10000" eternal="false"  timeToIdleSeconds="120" timeToLiveSeconds="240" overflowToDisk="false"/>
      
  <cache name="VerticeHB" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="3000" timeToLiveSeconds="6000" overflowToDisk="false"/>   
</ehcache>   


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 6:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show java code

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 7:56 am 
Newbie

Joined: Thu Oct 21, 2004 11:58 am
Posts: 3
I am developing a routing application. When i use 'Session' without close, it is faster that if open and close every time. Sometime it needs to check 200,000 vertex, and it must be very fast. Complete code is too large, but i show fundamental code.

Thanks again

The class'VerticeHB' is vertex object and AristaHB link object.
Code:
public static SessionFactory sessionFactory;
static{
   sessionFactory = new Configuration().configure().buildSessionFactory();
}

Session session = sessionFactory.openSession();
VerticeHB verticeHB;
// get initial vertex.
verticeHB = (VerticeHB) session.load(VerticeHB.class,new Long(id));
Vector vector = new Vector();
vector.add(verticeHB);
Iterator iterator;
AristaHB aristaHB;
while (vector.size()>0){
  //...
  // if (vertexFound) return;
  verticeHB = vector.remove(0);
  // get their links.
  Set set = verticeHB.getArista();
  iterator = set.iterator();
  while (iterator.hasNext()){
    aristaHB = (AristaHB) iterator.next();
    // we get next vertex of our route graph.
    vector.add((VerticeHB)aristaHB.getId2());
  }
  //...
}
ss.close();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 8:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you have to cache collection too

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 9:12 am 
Newbie

Joined: Thu Oct 21, 2004 11:58 am
Posts: 3
Thanks for reply quickly!
In the first post, i do not write all the code to simplify. I cache VerticeHB, AristaHB and VerticeHB.arista (the collection). Perhaps cache`s collection is wrong.
Thanks!

Complete mapping code:

Vertice.hbm.xml
Code:
<hibernate-mapping>
  <class name="VerticeHB" table="MLS.VERTICE" mutable="false" >
    <cache usage="read-only"/>
    <id name="id" column="id" type="long">
      <generator class="sequence">
        <param name="sequence">mls.vertice_seq</param>
      </generator>
    </id>
    <property name="x"/>
    <property name="y"/>     
    <set name="arista" lazy="true" inverse="true" >
      <cache usage="read-only"/>
      <key column="id_parent"/>
      <one-to-many class="AristaHB"/>
    </set>
  </class>
  <class name="AristaHB" table="MLS.V_ARISTA" mutable="false">
    <cache usage="read-only"/>
    <id name="idA" column="id_A">
      <generator class="sequence">
        <param name="sequence">mls.vertice_seq</param>
      </generator>
    </id>
    <many-to-one name="id1" column="id_parent" not-null="true" />
    <many-to-one name="id2" column="id_next" not-null="true" />
  </class>
</hibernate-mapping>


And ehcache.xml
Code:
<ehcache>
  <diskStore path="java.io.tmpdir"/>
  <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="240" overflowToDisk="false"/>
  <cache name="AristaHB" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="3000" timeToLiveSeconds="6000" overflowToDisk="false"/>
  <cache name="VerticeHB" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="3000" timeToLiveSeconds="6000" overflowToDisk="false"/>
  <!-- The collection -->
  <cache name="VerticeHB.arista" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="3000" timeToLiveSeconds="6000" overflowToDisk="false"/>
</ehcache>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 10:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what do you see in generated sql, for the 1st query execution and the second

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.