-->
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.  [ 4 posts ] 
Author Message
 Post subject: Benchmark - second reading with empty cache
PostPosted: Mon May 31, 2004 6:35 am 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
I am writing Graduation Thesis about Hibernate.

At the moment I am making some benchmark, to learn more about caching. (It's not meant for benchmark testing).

I inserted 5000 rows in a table with 15 columns.

I am getting the following output (time in ms):
first reading
1273.5168855260126
second reading with empty session and second level cache
? 935.3627346488647
third reading with empty session and second level cache
? 779.2289243461564
reading with using session cache
232.34265807503834
reading with using second level cache
245.84772645682096

All results are expected, except second and third reading with empty session and second level cache, witch are a bit low. I expect the results would bi similar to first reading. I don't thing it is because database caching because I did some testing with ASP.NET and I don't get the same behavior.

I would be very grateful for your help. I don't have anybody else to turn to.

Marko

Code:
------------------------------ CODE --------------------------------------------
System.gc();

timer.start();         
list = session.find("from Partner partner");      
timer.stop();            
out.write("first reading" + "\n");
out.write(timer.getDuration() + "\n");         
timer.reset();            

session.clear();
sessionFactory.evict(Partner.class);
System.gc();                             

timer.start();         
list = session.find("from Partner partner");      
timer.stop();               
out.write("second reading with empty session and second level cache" + "\n");              
out.write(timer.getDuration() + "\n");               
   timer.reset();

session.clear();
sessionFactory.evict(Partner.class);
System.gc();              
              
      timer.start();         
      list = session.find("from Partner partner");               
      timer.stop();                  
out.write("third reading with empty session and second level cache" + "\n");            
out.write(timer.getDuration() + "\n");
timer.reset();            

System.gc();
   
    list = new ArrayList();          
    timer.start();         
    i  = session.iterate("from Partner partner");      
    while (i.hasNext()) {
       list.add(i.next());
    }                  
    timer.stop();                       
out.write("reading with using session cache" + "\n");             
    out.write(timer.getDuration() + "\n");               
    timer.reset();
   
    list.clear();                             
       session.close();
System.gc();            
      
Session session2 = sessionFactory.openSession();
      timer.start();                      
      i  = session2.iterate("from Partner partner");      
    while (i.hasNext()) {
              list.add(i.next());
       }                  
      timer.stop();         
out.write("reading with using second level cache" + "\n");            
out.write(timer.getDuration() + "\n");
      timer.reset();
               
session.close();
sessionFactory.close();
System.gc();

----------------------------- PARTNER.HBM-------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
       
<hibernate-mapping>
   <class name="si.marko.hibernate.Partner" table="partner" proxy="si.marko.hibernate.Partner">
      <cache usage="read-write"/>
        <id name="id" column="ID" type="java.lang.Long">
           <generator class="native" />       
        </id>

        <property name="naziv" type="string" length="100" not-null="true"/>
        <property name="naslov" type="string" length="100"/>       
        <property name="posta" type="string" length="50"/>                       
        <property name="drzava" type="string" length="50"/>                       
        <property name="davcna" type="string" length="8"/>                       
        <property name="krajZaPlacila" column="kraj_za_placila" type="string" length="10"/>                       
        <property name="transRacSedez" column="trans_rac_sedez" type="string" length="5"/>                                               
        <property name="transRac" column="trans_rac" type="string" length="13"/>                       
        <property name="kontOseba" column="kont_oseba" type="string" length="50"/>                                                       
        <property name="tel" type="string" length="50"/>                       
        <property name="gsm" type="string"  length="50"/>                       
        <property name="email" type="string" length="50"/>                               
        <property name="www" type="string" length="100"/>                                       
        <property name="opomba" type="string" length="100"/>                                       
    </class>
</hibernate-mapping>
       
------------------- hibernate.cfg.xml ------------------------
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
   <session-factory>
      <property name="hibernate.connection.driver_class">
         com.newatlanta.jturbo.driver.DataSource
      </property>
      <property name="hibernate.connection.url">
         jdbc:JTurbo://marko:1433/kovinoplastika
      </property>
      <property name="hibernate.connection.pool_size">4</property>
      <property name="hibernate.connection.username">sa</property>
      <property name="hibernate.connection.password">marko</property>
      <property name="dialect">
         net.sf.hibernate.dialect.SQLServerDialect
      </property>
      <property name="hibernate.cache.use_query_cache">true</property>
      <property name="show_sql">false</property>
      <property name="transaction.factory_class">
         net.sf.hibernate.transaction.JDBCTransactionFactory
      </property>

      <property name="hibernate.c3p0.max_size">5</property>
      <property name="hibernate.c3p0.min_size">5</property>
      <property name="hibernate.c3p0.timeout">15000</property>
      <property name="hibernate.c3p0.max_statements">100</property>
      <property name="hibernate.c3p0.validate">true</property>

      <mapping resource="si/marko/hibernate/Partner.hbm" />
   </session-factory>
</hibernate-configuration>

 


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 12:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't know where to start here:

(1) Of course any timings not done in a loop are absolutely worthless.
(2) Reading from the second-level cache would not necessarily be any faster than reading from a local database cache
(3) You are not doing any transaction management (depending upon cache concurrency strategy, this means Hibernate will not even /use/ the second-level cache)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 2:53 pm 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Thank you. I am really grateful for your help and time.

Quote:
(1) Of course any timings not done in a loop are absolutely worthless.

Why? Because of Just In Time Compiling in Java? Database caching couldn't be a reason - I tested reading with JDBC, ADO, ADO.NET and second readings are not much lower then the firs one.

Quote:
(2) Reading from the second-level cache would not necessarily be any faster than reading from a local database cache

Second and third reading are with emptied both of caches (session.clear(); sessionFactory.evict(Partner.class);), so the time should bi similar to first one. This is what I don't understand.

Quote:
(3) You are not doing any transaction management (depending upon cache concurrency strategy, this means Hibernate will not even /use/ the second-level cache)

Based on my log, the second level cache is used. I hope I understood the log correctly. I added it bellow. (I filled only 3 records in table.)
I added transactions to my code (hopefully correct) and before first reading I read some data form another table to minimize the influence of JIT (had last one before but I didn't include it in a post).
The results are still the same (logging is of course off).

Thanks again,

Marko

Code:
------------------------------------ new code ------------------------------------
             SessionFactory sessionFactory;              
                 sessionFactory = new Configuration().configure().buildSessionFactory();          
          
             Transaction tx;
                 
               //************* Session cache *************
              
               final ITimer timer = TimerFactory.newTimer();
               Partner partner;      

               List list;
               Iterator i;


               Session session = sessionFactory.openSession();                
               tx = session.beginTransaction();              
               list = session.find("from Material material");
               tx.commit();

               System.gc();
         
               tx = session.beginTransaction();
               list = new ArrayList();      
               i  = session.iterate("from Material material");         
               while (i.hasNext()) {
                   list.add(i.next());
               }                  
               tx.commit();

               System.gc();
      
               System.out.println("DEBUG: first reading");
               tx = session.beginTransaction();
               timer.start();              
               list = session.find("from Partner partner");      
               timer.stop();            
               tx.commit();
               out.write("first reading" + "\n");
               out.write(timer.getDuration() + "\n");         
               timer.reset();            
           
               session.clear();
               sessionFactory.evict(Partner.class);
               System.gc();                             
           
               System.out.println("DEBUG: second reading with empty session and second level cache");
               tx = session.beginTransaction();              
               timer.start();         
               list = session.find("from Partner partner");      
               timer.stop();
               tx.commit();
               out.write("second reading with empty session and second level cache" + "\n");              
               out.write(timer.getDuration() + "\n");               
             timer.reset();

               session.clear();
               sessionFactory.evict(Partner.class);
               System.gc();              
                      
               System.out.println("DEBUG: third reading with empty session and second level cache");
               tx = session.beginTransaction();
            timer.start();         
            list = session.find("from Partner partner");               
            timer.stop();               
            tx.commit();
               out.write("third reading with empty session and second level cache" + "\n");              
               out.write(timer.getDuration() + "\n");
               timer.reset();            
      
               System.gc();
             
               System.out.println("DEBUG: reading with using session cache");              
              list = new ArrayList();          
              timer.start();
               tx = session.beginTransaction();
              i  = session.iterate("from Partner partner");      
              while (i.hasNext()) {
                 list.add(i.next());
              }                  
              tx.commit();
              timer.stop();                       
               out.write("reading with using session cache" + "\n");              
              out.write(timer.getDuration() + "\n");               
              timer.reset();
             
              list.clear();                             
             session.close();
               System.gc();            
            
               System.out.println("DEBUG: reading with using second level cache");              
               Session session2 = sessionFactory.openSession();
               tx = session2.beginTransaction();
            timer.start();                      
            i  = session2.iterate("from Partner partner");      
              while (i.hasNext()) {
                 list.add(i.next());
             }                      
            timer.stop();
            tx.commit();
               out.write("reading with using second level cache" + "\n");              
               out.write(timer.getDuration() + "\n");
            timer.reset();
                     
               session.close();
               sessionFactory.close();
               System.gc();              


-------------------------------- LOG - READING THREE RECORDS -----------------------

INFO  - Hibernate 2.1.2
INFO  - loaded properties from resource hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.jdbc.batch_size=0, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, hibernate.connection.password=marko, hibernate.connection.pool_size=1}
INFO  - using java.io streams to persist binary types
INFO  - using CGLIB reflection optimizer
INFO  - configuring from resource: /hibernate.cfg.xml
INFO  - Configuration resource: /hibernate.cfg.xml
INFO  - Mapping resource: si/marko/hibernate/Kategorija.hbm
INFO  - Mapping class: si.marko.hibernate.Kategorija -> kategorija
INFO  - Mapping resource: si/marko/hibernate/Artikel.hbm
INFO  - Mapping class: si.marko.hibernate.Artikel -> artikel
INFO  - Mapping resource: si/marko/hibernate/Inventura.hbm
INFO  - Mapping class: si.marko.hibernate.Inventura -> inventura
INFO  - Mapping resource: si/marko/hibernate/Material.hbm
INFO  - Mapping class: si.marko.hibernate.Material -> material
INFO  - Mapping resource: si/marko/hibernate/Normativ.hbm
INFO  - Mapping class: si.marko.hibernate.Normativ -> normativ
INFO  - Mapping resource: si/marko/hibernate/IzdaniRacun.hbm
INFO  - Mapping class: si.marko.hibernate.IzdaniRacun -> izdani_racun
INFO  - Mapping collection: si.marko.hibernate.IzdaniRacun.kategorija -> izdani_racun_kategorija
INFO  - Mapping resource: si/marko/hibernate/PostavkaIzdRac.hbm
INFO  - Mapping class: si.marko.hibernate.PostavkaIzdRac -> postavka_izd_rac

INFO  - Mapping subclass: si.marko.hibernate.PostavkaIzdRacObic -> postavka_izd_rac
INFO  - Mapping subclass: si.marko.hibernate.PostavkaIzdRacArt -> postavka_izd_rac
INFO  - Mapping resource: si/marko/hibernate/PrejetiRacun.hbm
INFO  - Mapping class: si.marko.hibernate.PrejetiRacun -> prejeti_racun
INFO  - Mapping collection: si.marko.hibernate.PrejetiRacun.kategorija -> prejeti_racun_kategorija
INFO  - Mapping resource: si/marko/hibernate/PostavkaPrejRac.hbm
INFO  - Mapping class: si.marko.hibernate.PostavkaPrejRac -> postavka_prej_rac
INFO  - Mapping resource: si/marko/hibernate/NormativIzdRac.hbm
INFO  - Mapping class: si.marko.hibernate.NormativIzdRac -> normativ_izd__rac
INFO  - Mapping resource: si/marko/hibernate/Partner.hbm
INFO  - Mapping class: si.marko.hibernate.Partner -> partner
INFO  - Configured SessionFactory: null
INFO  - processing one-to-many association mappings
INFO  - Mapping collection: si.marko.hibernate.IzdaniRacun.postavke -> postavka_izd_rac
INFO  - Mapping collection: si.marko.hibernate.PrejetiRacun.postavke -> postavka_prej_rac
INFO  - processing one-to-one association property references
INFO  - processing foreign key constraints
INFO  - Using dialect: net.sf.hibernate.dialect.SQLServerDialect
INFO  - Maximim outer join fetch depth: 1
INFO  - Use outer join fetching: true
INFO  - C3P0 using driver: com.newatlanta.jturbo.driver.DataSource at URL: jdbc:JTurbo://marko:1433/kovinoplastika
INFO  - Connection properties: {user=sa, password=marko}
INFO  - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
INFO  - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
INFO  - Use scrollable result sets: true
INFO  - Use JDBC3 getGeneratedKeys(): false
INFO  - Optimize cache for minimal puts: false
INFO  - echoing all SQL to stdout
INFO  - Query language substitutions: {no='N', true=1, yes='Y', false=0}
INFO  - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
INFO  - instantiating and configuring caches
INFO  - building session factory
INFO  - no JNDI name configured
INFO  - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
INFO  - starting query cache at region: net.sf.hibernate.cache.QueryCache
Hibernate: select material0_.ID as ID, material0_.naziv as naziv, material0_.enota as enota, material0_.opomba as opomba from material material0_
Hibernate: select material0_.ID as x0_0_ from material material0_
DEBUG: first reading
Hibernate: select partner0_.ID as ID, partner0_.naziv as naziv, partner0_.naslov as naslov, partner0_.posta as posta, partner0_.drzava as drzava, partner0_.davcna as davcna, partner0_.kraj_za_placila as kraj_za_7_, partner0_.trans_rac_sedez as trans_ra8_, partner0_.trans_rac as trans_rac, partner0_.kont_oseba as kont_oseba, partner0_.tel as tel, partner0_.gsm as gsm, partner0_.email as email, partner0_.www as www, partner0_.opomba as opomba from partner partner0_
DEBUG: second reading with emty session and second level cache
Hibernate: select partner0_.ID as ID, partner0_.naziv as naziv, partner0_.naslov as naslov, partner0_.posta as posta, partner0_.drzava as drzava, partner0_.davcna as davcna, partner0_.kraj_za_placila as kraj_za_7_, partner0_.trans_rac_sedez as trans_ra8_, partner0_.trans_rac as trans_rac, partner0_.kont_oseba as kont_oseba, partner0_.tel as tel, partner0_.gsm as gsm, partner0_.email as email, partner0_.www as www, partner0_.opomba as opomba from partner partner0_
DEBUG: third reading with emty session and second level cache
Hibernate: select partner0_.ID as ID, partner0_.naziv as naziv, partner0_.naslov as naslov, partner0_.posta as posta, partner0_.drzava as drzava, partner0_.davcna as davcna, partner0_.kraj_za_placila as kraj_za_7_, partner0_.trans_rac_sedez as trans_ra8_, partner0_.trans_rac as trans_rac, partner0_.kont_oseba as kont_oseba, partner0_.tel as tel, partner0_.gsm as gsm, partner0_.email as email, partner0_.www as www, partner0_.opomba as opomba from partner partner0_
DEBUG: reading with using session cache
Hibernate: select partner0_.ID as x0_0_ from partner partner0_
DEBUG: reading with using second level cache
Hibernate: select partner0_.ID as x0_0_ from partner partner0_
INFO  - closing



Top
 Profile  
 
 Post subject: Please, help me
PostPosted: Fri Jun 04, 2004 2:31 am 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Please, please, please. Can somebody help me? I spend A LOT OF TIME figuring this out. I tried all possible ways. Just give me a hint.

Why is second reading without session/secondary cache faster?

THANK YOU A LOT! I mean A LOT!

Marko


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