-->
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.  [ 8 posts ] 
Author Message
 Post subject: Hibernate Query Caching
PostPosted: Fri Jun 04, 2010 1:23 am 
Newbie

Joined: Fri Jun 04, 2010 1:03 am
Posts: 5
Dear all,

I'm using ehCache for caching the queries in order to achieve a better performance for my product that basically authenticates users.

Following is an extract from my ehcache.xml for the classes set for caching.

Code:
<cache name="com.xxx.xxx.xxxxxxxxx"
eternal="true" diskPersistent="true" overflowToDisk="true" />


With this setting, I'm observing that <class-name>.data & <class-name>.index files are created at the location specified in <diskStore>.

When trying to authenticate users for the first time, the time taken by every query takes a lot of time, while the subsequent authentications for the same user gets done quickly (obviously, because of the caching).

But in actual scenario, as the product being an authentication product, users will be authenticated only once (which is my first attempt that is far slower).

Therefore, requesting you experts to kindly suggest me an idea that I can implement to achieve a faster authentication on the first attempt itself please. Do let me know if you need any more info on the same.


Top
 Profile  
 
 Post subject: Re: Hibernate Query Caching
PostPosted: Sun Jun 06, 2010 5:40 am 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
Can you tell us more about your authentication mechanism.


Top
 Profile  
 
 Post subject: Re: Hibernate Query Caching
PostPosted: Mon Jun 07, 2010 12:34 am 
Newbie

Joined: Fri Jun 04, 2010 1:03 am
Posts: 5
Its just a basic user name-password based authentication.

As stated already, the objective is to achieve a better performance during the first authentication itself.
But currently, the behaviour is such a way that the authentication for all users takes a lot of time for the first time, while it gets considerably faster for the subsequent authentications.


Top
 Profile  
 
 Post subject: Re: Hibernate Query Caching
PostPosted: Mon Jun 07, 2010 2:25 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
I would implement a function manually which does all the relevant queries on startup of your application,
something like a cache-loader.


Top
 Profile  
 
 Post subject: Re: Hibernate Query Caching
PostPosted: Mon Jun 07, 2010 3:13 am 
Newbie

Joined: Fri Jun 04, 2010 1:03 am
Posts: 5
Currently, the problem is occuring on a per-user basis. First time authentication for every user takes a long time.

Assuming that I'm authenticating 2 users each of them getting authenticated 3 times (in a loop), the authentication timings are something like this...

Note - The authentication timings mentioned below are just references to the actual scenario observed.

Code:

===== User-1 =====

Time taken for authentication by User-1 (Iteration - 1) : 1000 mSec
Time taken for authentication by User-1 (Iteration - 2) : 500 mSec
Time taken for authentication by User-1 (Iteration - 3) : 350 mSec

===== User-2 =====

Time taken for authentication by User-2 (Iteration - 1) : 1100 mSec
Time taken for authentication by User-2 (Iteration - 2) : 650 mSec
Time taken for authentication by User-2 (Iteration - 3) : 350 mSec



Also, one more thing that I'm observing is objSession.commit() takes a long time (almost 25% of the total time taken for an authentication). Any ideas on how to reduce this please.

The final objective is to minimize the time taken for the first authentication by every user.


Top
 Profile  
 
 Post subject: Re: Hibernate Query Caching
PostPosted: Mon Jun 07, 2010 4:02 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
If the commit takes long time then usually it is because it takes long time for the flush-action.
Long flush time usually is due a large persistent context which means you loaded very many persistent objects into persistent context.
I suppose that you perform some unnecessary query which large result sets for the authentication procedure.
Can you please log your queries with p6spy and report the output here.


Top
 Profile  
 
 Post subject: Re: Hibernate Query Caching
PostPosted: Mon Jun 07, 2010 5:57 am 
Newbie

Joined: Fri Jun 04, 2010 1:03 am
Posts: 5
Configured p6spy to log the queries & following is the output from spy.log. Apologies for not publishing the log as is due to security constraints.

Code:
1275903332464|109|0|statement|
SELECT * FROM "null"|SELECT * FROM "null"
1275903334074|31|1|rollback||

1275903335589|93|2|statement|
statement for fetching the user info
1275903335589|-1||resultset|
resultset that returns the user information

1275903335761|93|2|statement|
statement for fetching the role of the user
1275903335777|-1||resultset|
resultset with user's role info
1275903335777|-1||resultset|
resultset with user's role info

1275903335996|125|2|statement|
statement for fetching the previous authentication details of the user 
1275903336011|-1||resultset|
resultset that returns the user authentication info

1275903336183|94|2|statement|
statement for checking whether the user actually possesses the credential to be authenticated
1275903336183|-1||resultset|
resultset that returs the details of the user credential

1275903337574|125|4|statement|
statement to fetch the actual credential from the database
1275903337574|-1||resultset|
resultset that returns the credential record from the database
1275903337652|47|4|rollback||

1275903337918|32|5|statement|
update statement that updates the user's authentication details
1275903337964|15|5|commit||
1275903338011|47|5|rollback||



Top
 Profile  
 
 Post subject: Re: Hibernate Query Caching
PostPosted: Tue Jun 08, 2010 6:25 am 
Newbie

Joined: Fri Jun 04, 2010 1:03 am
Posts: 5
any suggestions / corrections from you guys with which a better performance can be achieved during first attempt itself?


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