-->
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.  [ 11 posts ] 
Author Message
 Post subject: HQL Performance Issue
PostPosted: Tue May 25, 2010 9:47 am 
Newbie

Joined: Tue May 25, 2010 9:24 am
Posts: 5
Hi,
I’m using HQL to perform a query, this HQL Query takes approximately 500 ms to execute in a single thread, but with 20 threads it takes more than 10000 ms.
It seems that for each concurrent thread there is an increase of 30% in processing time.
This is not a connection pool issue because I have already checked that (the number of connections is above 20 and there’s no waiting time to obtain the connection).
When I try to do that query using hibernate SQLQuery the average time spent is 350 ms.

Using a profiling I get several times the following blocked code:
java.lang.Class.forName(String)
org.hibernate.util.ReflectHelper.classForName(String)
org.hibernate.util.ReflectHelper.getConstantValue(String)
org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.handleDotStructure(AST)
org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.visit(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(AST)
org.hibernate.hql.ast.util.NodeTraverser.traverseDepthFirst(AST)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(boolean)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(Map, boolean, String)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(Map, boolean)
org.hibernate.engine.query.HQLQueryPlan.<init>(String, String, boolean, Map, SessionFactoryImplementor)
org.hibernate.engine.query.HQLQueryPlan.<init>(String, boolean, Map, SessionFactoryImplementor)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(String, boolean, Map)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(String, boolean)
org.hibernate.impl.AbstractSessionImpl.createQuery(String)
org.hibernate.impl.SessionImpl.createQuery(String)



My hibernate properties are:

Code:
   
<util:map id="hibernateProperties">
      <entry key="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
      <entry key="hibernate.bytecode.use_reflection_optimizer"
         value="false" />
      
      <entry key="hibernate.transaction.auto_close_session"
         value="false" />
         
      <entry key="hibernate.transaction.flush_before_completion"
         value="true" />
      <entry key="hibernate.connection.release_mode"
         value="auto" />
      <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
      <entry key="hibernate.validator.apply_to_ddl" value="false" />
      <entry key="hibernate.show_sql" value="true" />
      <entry key="hibernate.schema_mapping" value-ref="schemaMapping" />
   </util:map>



Can anyone please help me?


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Tue May 25, 2010 12:15 pm 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
Could be session management issue. Even though you have several connections opened, may be they are not being managed. What are you using connection management. I think you should look into c3p0 for connection management.
Can you post your hibernate config and how you are running you query


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Tue May 25, 2010 12:32 pm 
Newbie

Joined: Tue May 25, 2010 9:24 am
Posts: 5
My database properties are in the context.xml in my webApp (folder META-INF)

Code:
<Context reloadable="false" path="/" cachingAllowed="false">
   <Resource name="jdbc/mydatasource" auth="Container" type="javax.sql.DataSource"
      factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
       driverClassName="oracle.jdbc.OracleDriver"
       accessToUnderlyingConnectionAllowed="true"
      url="jdbc:oracle:thin:@Mydevehr1:1521:DEV"
       username="MY_XXX" password="XXX"
       initialSize="20" maxActive="30" maxIdle="15" maxWait="30000"
      removeAbandoned="true" removeAbandonedTimeout="30"
      defaultAutoCommit="false" validationQuery="select 1 from dual" />
</Context>



Hibernate configurations:
Code:
   <bean id="dataSource" class="com.My.database.util.DataSourceWrapper" init-method="initialize">
      <constructor-arg>
         <bean class="org.springframework.jndi.JndiObjectFactoryBean">
             <property name="jndiName"><value>java:comp/env/jdbc/mydatasource</value></property>
         </bean>
      </constructor-arg>
   </bean>


   <bean id="MySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="configurationClass"
         value="com.My.persistence.base.utils.DynamicSchemaAnnotationConfiguration" />

        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties" ref="hibernateProperties" />

        <property name="annotatedClasses" ref="pfwRegistryModelClasses" />
    </bean>


<bean id="transactionManager"
       class="org.springframework.orm.hibernate3.HibernateTransactionManager">
       <property name="sessionFactory"><ref local="MySessionFactory"/></property>
   </bean>
   
   
   <util:map id="hibernateProperties">
      <entry key="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
      <entry key="hibernate.bytecode.use_reflection_optimizer"
         value="false" />      
      <entry key="hibernate.transaction.auto_close_session"
         value="false" />         
      <entry key="hibernate.transaction.flush_before_completion"
         value="true" />
      <entry key="hibernate.connection.release_mode"
         value="auto" />
      <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
      <entry key="hibernate.validator.message_interpolator_class"
         value="com.My.persistence.base.events.FWValidatorMessageInterpolator" />
      <entry key="hibernate.validator.apply_to_ddl" value="false" />
      <entry key="hibernate.show_sql" value="true" />
      <entry key="hibernate.schema_mapping" value-ref="schemaMapping" />
   </util:map>


   <bean id="myInternal" class="com.my.Class" scope="singleton">
      <property name="sessionFactory">
         <ref bean="MySessionFactory" />
      </property>
   </bean>

[quote]the bean that will execute the query[/quote]
   <bean id="myService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" scope="singleton">
      <property name="transactionManager">
         <ref bean="transactionManager" />
      </property>
      <property name="target">
         <ref bean=" myInternal " />
      </property>
      <property name="transactionAttributes">
         <props>
            <prop key="*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
         </props>
      </property>
   </bean>


The strange is that the SQLquery runs with a constant execution time, the HQLQuery seems that it have some problems instantiating the entities (classes) but it’s only my innocent opinion.
Any suggestions?


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Tue May 25, 2010 12:47 pm 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
I can suggest two things here
1) add property: hibernate.current_session_context_class = thread
2) use PROPAGATION_REQUIRES_NEW for insert and update


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Tue May 25, 2010 12:58 pm 
Newbie

Joined: Tue May 25, 2010 9:24 am
Posts: 5
I get the following Error:
org.hibernate.HibernateException: createQuery is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
at $Proxy57.createQuery(Unknown Source)


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Tue May 25, 2010 1:30 pm 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
session.beginTransaction() before each query


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Wed May 26, 2010 3:04 am 
Newbie

Joined: Tue May 25, 2010 9:24 am
Posts: 5
I believe that the transaction control is delegated in the "transactionManager" so I shouldn't need to do that, am I correct?


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Wed May 26, 2010 10:24 am 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
You may be right. I am new myself to Spring and I am using annotated transaction declaration. I think you would still have to define that in your DAO what is transacted.
Is there anyway you can post your DAO class here?


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Thu May 27, 2010 3:26 am 
Newbie

Joined: Tue May 25, 2010 9:24 am
Posts: 5
One thing that could be important that I forgot to measure is that there are 23 entities in the HQL Query, I starting to give up the using of HQL and use SQL, I’m almost sure that this could be a configuration issue (I don’t think that hibernate could have this kind of multi thread problems), If anyone have any clue please let me know,
Thanks for your help Ivirani :)


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Thu May 27, 2010 12:29 pm 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
You are welcome, sorry couldn't be too much of a help there. If you are writing complicated queries, look into Criteria. It really gives you a lot of flexibility.
Criteria criteria = session.createCriteria(entityName)
There you can use projections and restrictions to define different criteria and looks cleaner than regular HQL and SQL


Top
 Profile  
 
 Post subject: Re: HQL Performance Issue
PostPosted: Fri Jan 14, 2011 7:13 pm 
Newbie

Joined: Fri Jan 14, 2011 7:04 pm
Posts: 1
I have the same problem when running code in parallel in Spring. I was able to alleviate the situation a little bit by subclassing the Spring ThreadPoolTaskExecutor and setting the context classloader when a thread is created. That didn't help much because Hibernate constantly asks for classes that don't exist and then org.hibernate.util.ReflectHelper.classForName(String) falls through to Class.forName() again. Something is definitely wrong here and I would blame Hibernate were it not for the fact that I have never encountered this problem before with it.


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