File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Cacheing: Real Time Data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cacheing: Real Time Data" Watch "Cacheing: Real Time Data" New topic
Author

Cacheing: Real Time Data

Sameer Mhaskar
Greenhorn

Joined: Jul 13, 2005
Posts: 4
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


Thanks and Regards,<br />Sameer R. Mhaskar.<br />Technology Analyst
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30751
    
156

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)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sameer Mhaskar
Greenhorn

Joined: Jul 13, 2005
Posts: 4
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

Joined: Nov 13, 2006
Posts: 154
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

Joined: May 26, 2003
Posts: 30751
    
156

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cacheing: Real Time Data