aspose file tools*
The moose likes Performance and the fly likes Pagination & Session Management Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Pagination & Session Management" Watch "Pagination & Session Management" New topic
Author

Pagination & Session Management

Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
Hi All,

Currently we are working on displaying user specific search results.
Ideally for any pagination strategies we can choose from either a cache based (store resultsets in session) or query based (database call for each subset of rows to display). Each has it own merit.

In our situation we have to display 20 records each time to the user.
In our case to fetch the data subsets we have to make a web service call & not a database call. This web service also accepts a parameter of the number of records to fetch.
Since making a web service call everytime the user clicks next & fetch the 20 records to be shown on the screen will have a high latency & we also cannot opt for fetching all the records & storing it in session as we would be having a very high number of users accessing the system & storing all the resultsets in the session may not scale well.

With this regard we are thinking of adopting a hybrid approach where in we get 100 records, store it in the session & serve the user out of those first lot of 100 records from the session. Say when the user requests for data from 101-120 we make anther web service call , fetch the next set of 100 records & slam it into the same session variable replacing the first lot of 100.
Now say the user accesses the 91-100 we make a web service call again to fetch the first set of 100 records. So the web service calls to fetch the records will only happen at intervals of 91-100,101-110 & for all other requests like 71-80 or say 121-130 likes the data will be served from the session.


Do post your suggestions on the same.


Regards
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
I had done something similar before. I would also suggest looking at some of the java caching solutions. Some are open source.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Sounds like a reasonable strategy. When it comes time to retrieve the next block of 100 records, you may want to do that in a separate thread, so that the request for rows 91-100 doesn't have to wait until rows 101-200 have been retrieved.

It may also be advantageous to use a single shared cache rather than saving the record in the session. Particularly if your application is one in which multiple users are likely to be viewing the same records. Also it may be easier to manage the cache if it's in one place, so you can expire older entries, or reduce or expand the size of the cache based on available memory or performance tuning parameters. And yes, check out the available java caching solutions to save yourself some time.


"I'm not back." - Bill Harding, Twister
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Could you cache primary keys instead of complete records? Then you could retrieve individual records by key or use a range of keys to hit the db again. Might be worth the extra effort ... or not.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
raj vin
Greenhorn

Joined: Mar 17, 2007
Posts: 12
If user needs 91 to 110 records, Is it 2 web service calls ?
Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
Hi Raj,

Your are right. The second set of records from 101-200 is a separate webservice call.
Also the search results retrieved would be user specific & not shared amongst other users.

Regards,
ashish jadhav
Ranch Hand

Joined: Nov 20, 2008
Posts: 62
Hi mohit,
i am also working on same stub of web service in java.i created one web service which insert data in DB.but i want to set time interval to insert data in DB in specific time interval.can you please help me? how set time interval in java web service??
ashish jadhav
Ranch Hand

Joined: Nov 20, 2008
Posts: 62
I mean to say,stored records in cache and write to DB after specific time interval
eg. time interval= 2sec.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pagination & Session Management