-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: SessionFactoryImpl.checkNamedQueries
PostPosted: Mon Jun 06, 2005 11:20 pm 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
While building the session Factory, Hibernate 3 is invoking a checkNamedQueries. which seems to be a time consuming operation. Can some one tell me what exactly it is trying out and what if it is not doing that ?

-RV


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 12:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is pre-compiling all named queries. How many named queries do you have, and how long does it take?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 12:36 am 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
We have ~700 to 800 model classes and 922 named quries. The problem we are facing is in weblogic8.1 SP3 it is taking 4-5 minutes .

I did a profiling and found that checkNamedQueries is consuming the time.

And also we have more than 80 developers working on the CVS tree and even a single query problem is resulting in a build failure (startup).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 12:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
How *much* time?

What happens if you comment out the checkNamedQueries call?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 1:52 am 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
The exact timing information is (given by YourKit profiler)

Before commenting the checkNamedQueries :

buildSessionFactory() : 190,922 ms
checkNamedQueries() : 144,015 ms

After commenting the checkNamedQueries :

buildSessionFactory() : 21,188 ms

I just tried commenting the line and so far i couldn't find any errors because of that. In fact i dont know the impact. (i can send the full profile output if you like to see)

-RV


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 3:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
checkNamedQueries haven't been on the top before...weird.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 3:50 am 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
confused ?

checkNamedQueries() method is taking 144,015 ms under the following conditions.
---------------------------
Pentinum 2.8 GHz
Heap Max 1024
~700-800 model classes with ~900 queries
Weblogic 8.1 SP3

-RV


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 3:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what if you run this *outside* weblogic ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 3:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i'm suspecting weblogic might be having some chokes with the antlr and might do some very inefficient classloading (exceptions all over the place), but I dont have a weblogic so cant test it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 4:26 am 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
Max, infact it is giving me good result out side weblogic.

Is there any way to avoid checkNamedQueries as a stop gap since our development team is currently using weblogic and struggling. One another options is to fall back to hibernate2, which i am not favouring :)

Also can u pls tell me the impact of *Not calling* checkNamedQueries ?

-RV


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 5:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It simply just run through all your queries and built the query string.

If you don't do it at that time you will just pay for it lazily per query - which in your situation probably would be better.

BUT it would be very helpfull to find out why weblogic simply can't handle the parsing.

Things that could be interesting:

1. have you placed the antlr-x.x.H3 in weblogics lib as stated in the migration guide ?

2. Have you tried to enable to old classic querytranslator ? Does it also take forever to check ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 7:58 am 
Newbie

Joined: Mon May 31, 2004 2:52 am
Posts: 11
Max,

Thanks Max.

1. I put the antlr-2.7.5H3.jar in the PRE_CLASSPATH of weblogic.

2. I applied the patch - HHH-525

3. I tried with org.hibernate.hql.classic.ClassicQueryTranslatorFactory. There is no improvement in time.

Seems like the classloader is eating up the time..!!

-RV


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 9:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If 3 did not affect anything (did you check the logs if hibernate actually picked the old parser ?), then I don't have any better suggestions than to call weblogic support.

Because with the old parser we should be back to H2 behavior.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Just run a patched version of Hibernate with checkNamedQueries() commented. It has no bad impact at runtime.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 2:32 am 
Newbie

Joined: Thu Jun 01, 2006 2:05 am
Posts: 2
I faced the same issue a while back, so in case it's useful, some observations on why checkNamedQueries() is so slow on WebLogic.

First, some background: we have around 1600 named queries in our application. We support both WebLogic 8.1 SP4 and JBoss 4.0.3 RC1. The code base is pretty large, we have to bump the perm space up to 300M on WebLogic to avoid memory issues. On JBoss, checkNamedQueries() takes less than half a minute, while on WebLogic it takes around 5 1/2 minutes.

The following are the hibernate configuration properties we use:
Code:
hibernate.transaction.flush_before_completion=true
hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver
hibernate.cglib.use_reflection_optimizer=false
hibernate.transaction.manager_lookup_class=org.hibernate.transaction.WeblogicTransactionManagerLookup
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory
hibernate.cache.use_second_level_cache=false
hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N'
hibernate.jdbc.batch_size=0
hibernate.session_factory_name=eis.org.hibernate.SessionFactory
hibernate.connection.datasource=jdbc/TxSQLServer
hibernate.show_sql=false
hibernate.connection.provider_class=org.hibernate.connection.DatasourceConnectionProvider
hibernate.transaction.factory_class=org.hibernate.transaction.CMTTransactionFactory



My first patch was simply to comment out checkNamedQueries() from SessionFactoryImpl. However, I hadn't found this thread at that time and wasn't sure how safe it'd be, so I decided to delve a little deeper.

Using a debugger, I did find some interesting stuff; the following's an extract from a mail I sent to my team which explains the issue:

"First, for the upfront query compilation by Hibernate which takes up around half the startup time: slow classloading on WebLogic isn’t the main reason, it’s more of a combination of Hibernate issues and classloading. I was playing around with the debugger a bit, and I found that Hibernate calls Class.forName() or ClassLoader.loadClass() with class-names like ‘=’, ‘(‘, ‘)’, etc which obviously aren’t valid classes. What’s happening is this: while doing upfront compilation of named queries, Hibernate parses the queries into tokens and then tries to resolve many of the tokens (like ‘and’, ‘=’, ‘in’, etc) as Java classes for some reason. In the case of bad tokens, there’s a double overhead incurred before a ClassNotFoundException gets thrown: first ClassLoader.loadClass() is called on the context classloader and when that fails, Class.forName() is called. On WebLogic, multiple classloader levels (bootstrap, extension, system and application) are searched (probably twice) before it can be determined that a token is not a valid class, and this is really killing performance.

I patched Hibernate code to skip tokens which didn’t start with a Java identifier character or which were reserved HQL keywords. This seemed to do the trick; the time spent on upfront query compilation on my machine went from around 5 ½ min to less than 20 sec."

The patch mentioned above was applied to org.hibernate.hql.classic.QueryTranslatorImpl.getEntityPersisterUsingImports(String) and looks like:
Code:
    private static final String [] HQL_KEYWORDS = {"and", "like", "null", "or", "And",
            "OR", "in", "AND", "Or", "between", "IS", "upper",
            "LOWER", "lower", "LIKE", "IN", "NULL", "is"};

    private static final Set EXCLUDED = new HashSet(Arrays.asList(HQL_KEYWORDS));

    Queryable getEntityPersisterUsingImports(String className) {
        if (! Character.isJavaIdentifierStart(className.charAt(0)) ||
                EXCLUDED.contains(className)) {
            return null;
        }
        // ... Rest of existing code
     }


The above's obviously not good for production use, but it did the trick in our environment.

I'm a bit curious as to whether something similar to the above can be rolled in, viz. can Hibernate code ensure that it doesn't try to call Class.forName() or ClassLoader.loadClass() for tokens which definitely can't resolve to Java class names?

If you got this far, thanks for your patience!

Regards,
Hemanta


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.