-->
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.  [ 2 posts ] 
Author Message
 Post subject: Class.getInterfaces() takes 80% cpu time on repeated Query
PostPosted: Sat Jan 31, 2009 4:14 pm 
Newbie

Joined: Sat Jan 31, 2009 3:56 pm
Posts: 2
I'm running a query that returns ~ 100 objects per query in a loop that executes ~ 6000 times (iterating over a different search key for each query). I put some profiling code on the process since it was taking longer than I expected (-agentlib:hprof=cpu=samples,depth=10). Normally, I'd expect the process to be bound by the database, so most of the time would be spent waiting for SocketInputStream.socketRead0. However, this was not the case.

Instead, calls to java.lang.Class.getInterfaces() was consuming 80% of the processing time. The calls to getInterfaces() were occuring in the following stack trace:

java.lang.Class.getInterfaces
org.hibernate.intercept.FieldInterceptionHelper.extractFieldInterceptor
org.hibernate.intercept.FieldInterceptionHelper.clearDirty
org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary
org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity
org.hibernate.event.def.AbstractFlushingEventListener.flushEntities
org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions
org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush
org.hibernate.impl.SessionImpl.autoFlushIfRequired
org.hibernate.impl.SessionImpl.list
org.hibernate.impl.QueryImpl.list
org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate
org.springframework.orm.hibernate3.HibernateTemplate.execute
org.springframework.orm.hibernate3.HibernateTemplate.findByNamedParam

So (a) I'm calling the Query from Spring's HibernateTemplate wrapper and (b) all the getInterfaces calls are inside Hibernate code.

Is there anything I can do to increase the performance here? I get the impression that I'm taking some sort of reflection performance hit every time I create a new query. Perhaps there is some way to compile the query and mitigate this issue? Feel free to punt me to the Spring forum's if you think it would help.

Hibernate version:

Tried both 3.2.6.GA and 3.3.1.GA

Name and version of the database you are using:

MySQL 5.0.38

The generated SQL (show_sql=true):

select trip0_.id as id8_, trip0_.blockId as blockId8_, trip0_.blockSequenceId as blockSeq3_8_, trip0_.directionId as directio4_8_, trip0_.route_id as route9_8_, trip0_.routeShortName as routeSho5_8_, trip0_.serviceId as serviceId8_, trip0_.shapeId as shapeId8_, trip0_.tripHeadsign as tripHead8_8_ from gtdf_trips trip0_ where trip0_.blockId=?


Top
 Profile  
 
 Post subject: Found the Problem: Issue With Flushing Entities
PostPosted: Sat Jan 31, 2009 6:47 pm 
Newbie

Joined: Sat Jan 31, 2009 3:56 pm
Posts: 2
After running Hibernate through the debugger, I was able to figure out the problem. Hibernate seemed to be spending a lot of time in each query checking if the loaded entities were dirty and in need of flushing. In my application, the entities were not being modified in any way so they were effectively read-only for my purposes.

It seems you can pass a query hint for each query that specifies that the entities returned from the query should be marked read-only. I'm specifically using @NamedQuery annotations, so the "org.hibernate.readOnly" hint did the trick. See docs here:

http://www.hibernate.org/hib_docs/annot ... ml#d0e1859

The net effect is that now all the entities I'm loading up in my queries are marked read-only and don't require flushing. My data processing loops runs MUCH faster now.

Not sure if there is a better way of handling situation, so I'm open to suggestions.


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