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.  [ 7 posts ] 
Author Message
 Post subject: strange performance problems with stateless session, queries
PostPosted: Fri Nov 11, 2005 11:19 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hibernate version: 3.1 rc 2
DB2 7.2.9

We are using the stateless session to read large amounts of data.
We have two table A and B with lots of rows (e.g.200000) and many columns.
Both tables and mappings are flat, i.e. no collection etc.
The table are read with two queries queryA and queryB.
The performance and memory consumption
of the queries differ in suprising ways depending
on some circumstances.

Here are some performance results for different szenarios:

1. StatelessSession
using queryA.list(), 20 sec
using queryB.list(), 33 sec
Memory Usage 350 MB

2. StatelessSession
using queryA.list(), 21 sec
using queryB.scroll() 1600 sec
Memory Usage 180 MB

3. StatelessSession
using queryA.list(), 21 sec
session.close and reopen
using queryB.scroll() 65 sec
Memory Usage 180 MB

4. StatelessSession
no queryA
using queryB.scroll() 65 sec
Memory Usage 25 MB

5. StatelessSession
using queryA.scroll() 21
using queryB.scroll() 63
Memory Usage 55 MB

6. (Stateful) Session
using queryA.list(), 20 sec
using queryB.scroll() 79 sec
Memory Usage 450 MB

Some remarks:
The problem is that queryB is 10 time slower in scenario 2.
The performance of the two queries should be independent of each other
in szenarios 1 and 2.
The memory consumption of stateless session is too large,
when using query.list().
The problem grows with the number of rows of table A.
There seems to be some kind of loop over all previous loaded
instance of A, when loading B via scroll.
SQL output consist only of the two queries.
Profiling with YourKit didnt reveal anything.

Any help would be appreciated.
Here are the files:

Code:
   private static void queriesCursor(SessionFactory factory) {
      StatelessSession session = factory.openStatelessSession();
      Transaction tx = session.beginTransaction();
      
      long t0 = System.currentTimeMillis();
      Query queryA = session.createQuery("from A");
      List listA = queryA.list();
      System.out.println("query A: " + (System.currentTimeMillis()-t0) +  " cnt: " + listA.size());

      t0 = System.currentTimeMillis();
      Query queryB = session.createQuery("from B");
      ScrollableResults scroll = queryB.scroll();
      int cnt=0;
      while (scroll.next()) {
         B b = (B) scroll.get(0);
         b.getId();
         cnt++;
      }
      System.out.println("query B: " + (System.currentTimeMillis()-t0) +  " cnt: " + cnt);
      
      tx.commit();
   }


hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

    <session-factory>
        <!--<property name="hibernate.hbm2ddl.auto">update</property> -->
       
        <property name="dialect">org.hibernate.dialect.DB2Dialect</property>
        <property name="hibernate.default_schema">hib</property>
        <property name="connection.driver_class">COM.ibm.db2.jdbc.app.DB2Driver</property>
        <property name="connection.username">ifb</property>
        <property name="connection.password">kennwort</property>
        <property name="connection.url">jdbc:db2:dbtest</property>
        <property name="jdbc.batch_size">20</property>
        <!--<property name="hibernate.default_batch_fetch_size">20</property>-->
        <property name="show_sql">true</property>
        <property name="hibernate.cache.use_second_level_cache">false</property>
        <property name="hibernate.connection.release_mode">on_close</property>

      <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
      <property name="c3p0.acquire_increment">1</property>
      <property name="c3p0.idle_test_period">100</property>
      <property name="c3p0.max_size">100</property>
      <property name="c3p0.max_statements">100</property>
      <property name="c3p0.min_size">1</property>
      <property name="c3p0.timeout">100</property>
      
        <!-- Mapping files -->
        <mapping resource="test/A.hbm.xml"/>
        <mapping resource="test/B.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


The classes A, B and corresponding table contain just simple doubles, int, Date etc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 11:59 am 
Do you have 2nd-level caching enabled for A and/or B? That would explain the large memory consumption. If you only need to read and process the data once, you should be better off without caching.

Or if the data is just in the session cache, you can evict each object after you have read it. Paragraph 20.3 of the manual gives an example.


Top
  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 12:16 pm 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Thanks fljmayer,

fljmayer wrote:
Do you have 2nd-level caching enabled for A and/or B? That would explain the large memory consumption. If you only need to read and process the data once, you should be better off without caching.


second level cache is disabled via hibernate.cfg.xml:
Code:
<property name="hibernate.cache.use_second_level_cache">false</property>


and our app is logging:

Code:
11.11.2005 17:14:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: disabled
11.11.2005 17:14:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled


fljmayer wrote:
Or if the data is just in the session cache, you can evict each object after you have read it. Paragraph 20.3 of the manual gives an example.


We like to use stateless session, which (as far as I understand it) has no session cache and no evict methods.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 12:47 pm 
The Hibernate Session does have a cache and an evict() method.
Please take a look at paragraph 20.3 in the Hibernate online manual.


Top
  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 3:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
he is talking about StateLess session...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 3:47 pm 
Oops sorry, still on 3.0.5.


Top
  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 9:24 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Please read:

http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1157


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