Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading a cache in servlet init method

 
Jaideep Kshirsagar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am loading a cache in 'init' method of servlet. The cache holds various exceptions which are sent to different exception buckets on screen.

Now as the number of exceptions are too high, it takes a long time (around 30 min) to load the cache. Untill the cache is loaded the servlet does not show up.
So servlet start up time is causing performance issues.

Is there any way through which first exception cacheing is handled by some script or different method in servlet and then the servlet comes up?

How to reduce the start up time for this servlet, considering amount of cacheing required? Please let me know if any more information is required.

TIA.

Rgds,
Jai
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the servlet need the cache for its work? If so, I don't see a way around waiting for that time until it can assume operation. If not, I'd move the cache initialization to a ServletContextListener that runs independently of any servlet.
 
Jaideep Kshirsagar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Servlet uses the cache in doGet method, any option through which I can load the cache before servlet startup just use it in servlet?

Regd,
Jai
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) attack the load method to see if you can speed it up
2) make the cache load in a separate thread and only make the loaded parts available to the Servlet
eg

3) once again load in a separate thread, but allow the SErvlet to load the data it needs too

Note that it is not always a problem if the data gets loaded from both sides.
4) Don't use caching

if you let go of the idea that the cache needs to be 100% before it is useful, you can slowly improve your performance while the cache fills.
 
Imtiyaz Ahmed
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u may get benefitted by using <load-on-startup> tag in DD.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Imtiyaz Ahmed:
u may get benefitted by using <load-on-startup> tag in DD.


Please use real words when posting to the forums. Abbreviations such as "u" in place of "you" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
 
Jaideep Kshirsagar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am not sure how <load-on-startup> tag will benefit me in this case, I am already using it with value as '1', as the concerned servlet should be the first one to get loaded.

The problem is that due to cacheing happening in 'init(servletConfig)' method, load up time is shooting up.

I dont have a fare clue if a perl script can do my job (cacheing) beforehand and I can just use the object wherever required. I am also not definitely aware if using 'init()' method for cacheing will help. Any insights on this?

Rgds,
Jai
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaideep Kshirsagar:
I am not sure how <load-on-startup> tag will benefit me in this case

It won't. Context listeners have made load-on-startup obsolete for pre-initializing web apps.
 
Sanjay Kannan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The cache holds various exceptions which are sent to different exception buckets on screen."

What data does the cache contains. You might want to do lazy initialization. Load the cache with data which has been used, so you can prevent the loading of huge data when the servlet starts up.

But i am not sure if you need all the data for display or something that sort.
 
Jaideep Kshirsagar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This information may be of help -

The cache holds various exceptions which are sent to different exception buckets on screen.

This means that it is a gui to display exceptions occured while processing.

What data does the cache contains.

Cache consists of various hashmaps containing exception objects of various types.

But i am not sure if you need all the data for display or something that sort.

Yes, I would need the entire data for displaying exceptions on screen.

Thank you,
Jai
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic