• Post Reply Bookmark Topic Watch Topic
  • New Topic

Solving for Page With Slow Response Time  RSS feed

 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Actually, what I intended to do is something like the topic "Threading in Servlet" posted
recently.
In one of my module, the response time is very
slow because it retrieves quite a number of
records from the database. After that, they need
to be process before sending to the JSP page.
It would be pretty nice if someone could suggest
a good way to solve the problem because the user
can't just sit there waiting minutes for the page to be loaded.
Threading seems to be a possible solution but I
do realized a few issues:
1) If I would to reload the JSP page every
minutes, wouldn't it look awful?
2) If there is a paging mechanism in place
and the user select a page which is not even
available, how should I handle it?
I do hope that I can get ideas as I can't seem
to come out with a good solution.

Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66156
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This comes up a lot. Point is, there's only so much information that's useful at a time. If you wait many minutes for 10,000 rows of data to display, is it really useful to anyone?
You mentioned paging, and that's usually one of the solutions that solves two problems: response is reasonable because only a small data set is processed at a time, and users are not overwhelmed with too much data to mentally process.
Search through these forums for "paging". The topic has been discussed many times.
hth,
bear
 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I don't see how paging can solve the problem well. And by the way, I had actually implemented the pagination.
I see 2 ways of database access for paging.
1) select everything we want and then put them
in session (this is how my pagination done);
no further database access for subsequent
pages choosen
2) select only records needed in the page and
access database again if another page choosen
eg: page 1 - select record 1-10
page 2 - select record 11-20
The only way I see how paging can solve response time is by using method 2. Method 2 seemed to be a nice approach with database like mySQL but not with Oracle, Informix, etc. Reason is because mySQL have function to select records in such a way. In Oracle, for example, there is no direct way though it can be achived.
Any comments.

Thanks in advance.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question for Jamess about this... select everything we want and then put them
in session (this is how my pagination done);
no further database access for subsequent
pages choosen


What exactly do you mean by "them". (what are you putting in the session?).

I've heard and I basically believe it.. that it's a real bad idea to shove database items like connections, resultsets, etc.. into a session variable. Because of course that's a resource hog.

But also, the ResultSet doesn't actually contain ALL the rows returned by your query. The database and driver will marshall data as needed. So only until your rs.next() method hits against the end of the current bunch of records will your driver make a request and the db sends the next bunch.

To you the programmer, it looks like the RS is complete and ready, but in fact it isn't: which is why, when I think of it.. there's no such method as rs.totalRecords() or why you can't disconnect a ResultSet from it's Connection.
Anyways... if you're placing the resultset into the session, then slowdowns can still occur when you get to the 'next page' of data, because the resultset has to wait for the next bunch of rows. (So I guess I'm refuting the 'no further database access' comment, IFF you are putting the resultset into the session).
 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,
Sorry for the vague part.
Actually what I'm tried to say is that I select the records I wanted and add them to an ArrayList by looping through the resultset. The created List would be placed in the session and therefore, no further database access is needed.
The database connection would be closed even before the creation of the ArrayList.

Thanks.
 
qu shihong
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is realy a hard nut to crack .
In Application Server,if you put all the records into session once,it is a resource hog without fail.But if you do not,you have to connect and disconnect frequently,because the connectionPoll's connection number is finite.So I do it in this way : put all the primary key into session and select the record from database by primary key when require.But I know,this is not the best way yet.
[ February 27, 2003: Message edited by: qu shihong ]
 
Zabe Agha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James, I don't want to get off topic, so stop me as soon as you think that what I'm saying may not be applicable.
Question: Does EVERY user accessing your page have to do a new DB query. In other words, is it important for every user to see a fresh DB result set?
If not, perhaps you can implement JSP-level caching of your page so that only one user takes the hit of the large page, and every user after that sees the cached output, resulting in no DB access at all.
If this is interesting for you, let me know and we can persue it further.
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To James Gordon
About method 2, do you mean that MySQL supports paging very well? And how? thanks
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ken Shamrock:
To James Gordon
About method 2, do you mean that MySQL supports paging very well? And how? thanks

they hv a nice way to write your "select" query...
eg. select * from <tablename> limit <start-index>,<no-of-records>
hth
MB
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
couple of thoughts on this:
- are you using ejbs and an app.server. If so you can use entity beans.
- also software patterns like value objects, page iterator seem viable.
- take a look at what is causing the delay. Is it really the database, or is it creationof the html at the servlet, or maybe rendering of the page to/in the browser.
- use of gzip encoding may be usefull if sending large sets of info to the browser
- the delay in the database may be caused by you sql statement(eg. use of *) or inproper use of indexes.
conclusion : it could be a lot of things in all different layers.
cheers,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!