-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate over 50% slower with C3P0?
PostPosted: Fri Feb 08, 2008 5:53 pm 
Newbie

Joined: Fri Feb 08, 2008 5:27 pm
Posts: 2
I am running a simple test which inserts 1000 items into a database. When I run the test without connection pooling, the test completes in about 900ms. When I add C3P0 connection pooling, the test takes around 1400ms. The timing doesn't start until after the SessionFactory has been created, so the difference isn't attributable to that. I tried executing one insert before the timer starts in case the first insert has some one-time overhead, but it had no effect.

The only difference between the two tests is the following properties are added to the hibernate.cfg.xml file:

Code:
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>

Am I doing something wrong? Shouldn't the connection pooling speed things up dramatically?

Hibernate version: 3.2
Name and version of the database you are using: SQL Server 2005 Express

Hibernate configuration:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
      <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:jtds:sqlserver://SERVER/Test;instance=SQLEXPRESS;namedPipe=true</property>
      <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
      <mapping resource="com/nextpage/domain/dto/TestItem.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="com.nextpage.domain.dto.TestItem" table="TestItem">
      <id name="id" column="id"><generator class="guid"/></id>
   </class>
</hibernate-mapping>


Code:
Code:
package com.nextpage.domain.dto;

public class TestItem
{
   private String id;

   public TestItem()
   {
   }

   public String getId()
   {
      return id;
   }

   private void setId(String id)
   {
      this.id = id;
   }
}


Code:
import com.nextpage.domain.dto.TestItem;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Main
{
   private static void testInsert(SessionFactory sessionFactory)
   {
      Session session = sessionFactory.openSession();
      try
      {
         Transaction tx = session.beginTransaction();
         TestItem item = new TestItem();
         String itemId = (String)session.save(item);
         tx.commit();
      }
      finally
      {
         session.close();
      }
   }

   public static void main(String[] args) throws Exception
   {
      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
      try
      {
         testInsert(sessionFactory);
         long start = System.currentTimeMillis();
         for (int i = 0; i < 1000; ++i)
         {
            testInsert(sessionFactory);
         }
         System.out.println(System.currentTimeMillis() - start + "ms elapsed");
      }
      finally
      {
         sessionFactory.close();
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 09, 2008 9:06 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
I assume that hibernate uses already connection pooling. When it has, the hibernate connection pool algorithm together with CP30 connection pooling algorithm can result in unpredictable behaviour. Therefore the question is whether it is a logical and compliant choice to add a connection pool like CP30 to Hibernate. But to be honest, I don't know whether Hibernate is already implementing a connection pool, but I assume it does.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 2:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I would expect you are seeing the initial connection pool being created and the initial connection itself - I would assume the first timing figure would be longer than the following for each loop. A one time cost of the initial connection is nothing in terms of the performance of a deployed application.

BTW: Hibernates inbuilt connection pool is not recommended for production use - so using C3P0 is a good choice.


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