-->
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.  [ 5 posts ] 
Author Message
 Post subject: hibernate.cfg.xml config - datasource - pool_size - how to
PostPosted: Fri Apr 02, 2004 2:38 pm 
Newbie

Joined: Fri Nov 28, 2003 9:08 am
Posts: 19
Location: Brasil
Hi,

I had some preformance issues with my production environment. So I tried some things. I am in doubt about hibernate configuration.

Environment:
Tomcat 4-1-29

begin webapps/myapp.xml
----------------------------------------------------------------------------------
<Context path="/rinoceronte" swallowOutput="true" docBase="rinoceronte.war" debug="0">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="rinoceronte." suffix=".txt" timestamp="true"/>
<Resource name="jdbc/rinoceronte" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/rinoceronte">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>50</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>net.sourceforge.jtds.jdbc.Driver</value>
</parameter>
<parameter>
<name>defaultAutoCommit</name>
<value>false</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:jtds:sqlserver://localhost:1433/TatilDesign</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>
</ResourceParams>
</Context>
----------------------------------------------------------------------------------
end webapps/myapp.xml

begin hibernate.cfg.xml (some of it)
----------------------------------------------------------------------------------
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/rinoceronte</property>
<property name="use_outer_join">true</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.SybaseDialect</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>

<property name="dbcp.maxActive">100</property>
<property name="dbcp.whenExhaustedAction">1</property>
<property name="dbcp.maxWait">60000</property>
<property name="dbcp.maxIdle">10</property>
<property name="dbcp.ps.maxActive">100</property>
<property name="dbcp.ps.whenExhaustedAction">1</property>
<property name="dbcp.ps.maxWait">60000</property>
<property name="dbcp.ps.maxIdle">100</property>
<property name="connection.provider_class">net.sf.hibernate.connection.DatasourceConnectionProvider</property>
<property name="connection.pool_size">1</property>
<property name="statement_cache.size">25</property>
----------------------------------------------------------------------------------
end hibernate.cfg.xml

hibernate version 2.1.2

I am not sure about <property name="connection.datasource">java:comp/env/jdbc/rinoceronte</property>

Is this correct? Is it accordingly to myapp.xml??

What about connection.pool_size, connection.provider_class and statement_cache.size? I am not sure if I have to declare these. Are these values ok? Production env is about 100 havy users (intranet app).

Any suggestions to performance gain?

Tks
Felipe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 3:09 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
Felipe,

I am using Resin 2.1.12 with Hibernate 2.1.2 and using the Resin Connection pool with Hibernate in the following manner.

hibernate.cfg.xml

Code:
<session-factory>
    <property name="hibernate.connection.datasource">java:comp/env/hibernate/sapdb/alltel</property>
    <property name="dialect">net.sf.hibernate.dialect.SAPDBDialect</property>
    <property name="show_sql">true</property>
    <property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property>
    <property name="hibernate.cglib.use_reflection_optimizer"> false</property>
</session-factory>


The corresponding connection pool in the resin.conf is as follows:

Code:
  <resource-ref>
    <res-ref-name>hibernate/sapdb/alltel</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <init-param driver-name="com.sap.dbtech.jdbc.DriverSapDB"/>
    <init-param url="jdbc:sapdb://foo.bar.com/FOO"/>
    <init-param user="FOOUSER"/>
    <init-param password="bar"/>
    <init-param max-connections="20"/>
    <init-param max-idle-time="30"/>
  </resource-ref>

I control the connection pool size and the idle time in this configuration. Do you have something similar to this in the application server you are using?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 8:08 am 
Newbie

Joined: Fri Nov 28, 2003 9:08 am
Posts: 19
Location: Brasil
Hi,

tks for the reply.

I am not very familiar with these JNDI and data source configurations. So I used some I found on the net.

I am using only Tomcat web conteiner, and no app server. My soubt is: will hibernate use tomcats config to get info about pool size and so on, or will it use hiberntae.cfg.xml config to get the same info?

in myapp.xml, there is:
Code:
<Context path="/rinoceronte" swallowOutput="true" docBase="rinoceronte.war" debug="0">

    <Logger className="org.apache.catalina.logger.FileLogger"
        prefix="rinoceronte." suffix=".txt" timestamp="true"/>

  <Resource name="jdbc/rinoceronte" auth="Container" type="javax.sql.DataSource"/>
 
  <ResourceParams name="jdbc/rinoceronte">
      <parameter>
          <name>factory</name>
          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
      </parameter>
      <parameter>
          <name>maxActive</name>
          <value>50</value>
      </parameter>
      <parameter>
          <name>maxIdle</name>
          <value>10</value>
      </parameter>
      <parameter>
          <name>maxWait</name>
          <value>10000</value>
      </parameter>     
      <parameter>
          <name>username</name>
          <value>sa</value>
      </parameter>
      <parameter>
          <name>password</name>
          <value></value>
      </parameter>
     <parameter>
        <name>driverClassName</name>
        <value>net.sourceforge.jtds.jdbc.Driver</value>
     </parameter>
      <parameter>
          <name>defaultAutoCommit</name>
          <value>false</value>
      </parameter>
     <parameter>
        <name>url</name>
        <value>jdbc:jtds:sqlserver://localhost:1433/TatilDesign</value>
     </parameter>
      <parameter>
          <name>removeAbandoned</name>
          <value>true</value>
      </parameter>
      <parameter>
          <name>removeAbandonedTimeout</name>
          <value>60</value>
      </parameter>
      <parameter>
          <name>logAbandoned</name>
          <value>true</value>
      </parameter>
  </ResourceParams>
     

</Context>


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

<hibernate-configuration>

    <session-factory>
      
      <property name="connection.datasource">java:comp/env/jdbc/rinoceronte</property>
         
      <property name="use_outer_join">true</property>
      <property name="show_sql">false</property>
        <property name="dialect">net.sf.hibernate.dialect.SybaseDialect</property>
      <property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>

      <property name="dbcp.maxActive">100</property>      
      <property name="dbcp.whenExhaustedAction">1</property>      
      <property name="dbcp.maxWait">60000</property>      
      <property name="dbcp.maxIdle">10</property>      
      <property name="dbcp.ps.maxActive">100</property>      
      <property name="dbcp.ps.whenExhaustedAction">1</property>      
      <property name="dbcp.ps.maxWait">60000</property>      
      <property name="dbcp.ps.maxIdle">100</property>      
      <property name="connection.provider_class">net.sf.hibernate.connection.DatasourceConnectionProvider</property>      
      <property name="connection.pool_size">1</property>      
      <property name="statement_cache.size">25</property>      
      
      

      
        <!-- Mapping files -->
        <!-- End Mapping files -->

    </session-factory>

</hibernate-configuration>


See that there is maxActive config in both. Wich one will be used?

Tks
Felipe


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 8:17 am 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
If you are using a JNDI Datasource, you should probably remove pool related configurations from your hibernate.cfg.xml file. That will ensure that Hibernate hands off connection related issues to your Datasource. To be honest with you, I have never researched what would happen if both had these configurations. But I can safely say that if you leave them in your Datasource mapping instead of the hibernate.cfg.xml, they will get used properly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 8:53 am 
Newbie

Joined: Fri Nov 28, 2003 9:08 am
Posts: 19
Location: Brasil
when I start my tomcat, log is as follow:

Code:
09:49:25,062  INFO Configuration:629 - processing foreign key constraints
09:49:25,296  INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.SybaseDialect
09:49:25,312  INFO SettingsFactory:62 - Use outer join fetching: true
09:49:25,328  INFO ConnectionProviderFactory:53 - Initializing connection provider: net.sf.hibernate.connection.DatasourceConnectionProvider
09:49:25,343  INFO NamingHelper:26 - JNDI InitialContext properties:{}
09:49:25,406  INFO DatasourceConnectionProvider:51 - Using datasource: java:comp/env/jdbc/rinoceronte
09:49:25,421  INFO TransactionFactoryFactory:31 - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
09:49:25,437  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
09:49:26,031  INFO SettingsFactory:102 - Use scrollable result sets: true
09:49:26,031  INFO SettingsFactory:105 - Use JDBC3 getGeneratedKeys(): true
09:49:26,031  INFO SettingsFactory:108 - Optimize cache for minimal puts: false
09:49:26,031  INFO SettingsFactory:117 - Query language substitutions: {}
09:49:26,046  INFO SettingsFactory:128 - cache provider: net.sf.ehcache.hibernate.Provider
09:49:26,046  INFO Configuration:1080 - instantiating and configuring caches
09:49:26,546  INFO SessionFactoryImpl:119 - building session factory
09:49:27,234  INFO ReflectHelper:160 - reflection optimizer disabled for: br.com.tatil.rinoceronte.model.Proposta, BulkBeanException: null (property setDescricao)
09:49:27,546  INFO ReflectHelper:160 - reflection optimizer disabled for: br.com.tatil.rinoceronte.model.ProjetoFaseModelo, NullPointerException: null
09:49:27,640  INFO ReflectHelper:160 - reflection optimizer disabled for: br.com.tatil.rinoceronte.model.ItemEstoque, NullPointerException: null
09:49:27,671  INFO ReflectHelper:160 - reflection optimizer disabled for: br.com.tatil.rinoceronte.model.Cliente, BulkBeanException: null (property setRazaoSocial)
09:49:27,765  INFO ReflectHelper:160 - reflection optimizer disabled for: br.com.tatil.rinoceronte.model.Projeto, BulkBeanException: null (property setDescricao)
09:49:27,828  INFO ReflectHelper:160 - reflection optimizer disabled for: br.com.tatil.rinoceronte.model.ProjetoFase, NullPointerException: null
09:49:27,875  INFO ReflectHelper:160 - reflection optimizer disabled for: br.com.tatil.rinoceronte.model.PropostaFase, NullPointerException: null
09:49:28,390  INFO SessionFactoryObjectFactory:82 - no JNDI name configured


The last line shows SessionFactoryObjectFactory:82 - no JNDI name configured.
So I am actually not sure if I am using JNDI or not.
myapp.xml showed above does not configure JNDI datasource?


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