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

Cacheing: Real Time Data

 
Sameer Mhaskar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need to find a way to improve performance of my application. here is the scenario,

Its a J2ee application. The client will send the request to the servlet (programmatic) after every 10 seconds. The servlet will query the database and return the results. Currently there are few users but in future when the user base increases, this approach wont work as there will be many concurrent requests and hence load on the database and the application.

I was thinking of writing a thread which will ping the database after every 10 seconds and store the "Superset" of the data in an application wide object (e.g. a table structure in app context). The servlet will query this object instead of the database on each request.

Is it a right approach? Also in case of "Clustered Environment" will this work? My concern is whether app. context is replicated over clusters?

Can any one suggest me a better approach or tell me if I am missing something.

Any help is really appreciated

Thanks,
Sameer
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sameer,
This is a good approach. Do you have users 24 hours a day? If not, you might want to write it so you only go to the database if there has not been a request in the last <however long>. That way you don't have database traffic all day even when nobody is on the system.

Some servers have built in caching layers - you might want to check if yours does before writing your own. A built in cache will replicate across a server. Your own will not.

Which turns into a question of whether your application can tolerate data that is X seconds out of date. Some threshold is usually ok because you can't guarantee the data will be correct by the time the user sees it anyway. (processing, network traffic and the like)
 
Sameer Mhaskar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne,

Its a position monitoring system for a stock lending application. The users are logged in all the time but the data which is around 10 seconds old is tolerated. That is the reason I was planning to write a thread and update the data in cache every 10 seconds. I am using Web logic in a clustered environment. How can I use caching mechanism in Web logic? Any thoughts...


Sameer
 
Ajay Saxena
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cache refresh strategy you are planning to adopt will work for a single standalone server.

In a clustered environment,you either need to use a distributed cache (such as memcache,EH cache etc) OR build a mechanism to ensure local cache consistency using some messaging system such as JMS.
[ August 30, 2008: Message edited by: Ajay Saxena ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sameer Mhaskar:
I am using Web logic in a clustered environment. How can I use caching mechanism in Web logic? Any thoughts...

I don't use WebLogic, but a quck search found an article about commands which sounds equivalent to what I am using.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic