• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Help needed- Options for increasing performance

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok- I have a jsp page that has a huge list of data values(in a select box) and I need to dramatically increase performance/decrease download time. I'm already overriding the ServletOutputStream and using GZIP encoding. With this large list of values which is static, what are my options. Right now I'm using a buffered inputstream and reading it in from a file- I then put it in a session variable, and put it into the page.
How do I dramatically decrease the download time?
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Other details- the page is mostly dynamic, with the exception of the large list of data values.
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that you can't in some way filter the set of data that you actually need to display. . .
Couple of ideas, none of which are guaranteed to decrease the time, but might spark some ideas. .
- generate the <input type="select"> text and store it as a whole, rather than storing the set of values and then generating the select
- store it at application level, rather than session (so as not to take up more space than necessary)
- use a custom tag?
- use a JavaBean that stores the values in a HashMap or stores it as a set of text? (maybe both - the Hashmap for access for business logic, the text for quick retrieval to insert into the page)
You definitely don't want to have to read the file more than necessary, and you don't want to have to generate the HTML more than necessary.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have copy of a book "Java Performance and Scalability, vol. 1" by Bulka - published by O'Reilly. He does a lot of testing various approaches to improve performance. One method is to avoid writing String variables because of the character by character Unicode to byte translation. He suggests using byte arrays for static data.
I am curious as to how much improvement you got by switching to a GZIP encoded output stream.
Bill
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one more thing can also be done is to use page cachinng mechanism.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William- when I measuered the download time for using GZIP encoding, I saw a 50% improvement in download time.
The biggest hurdle we have is getting people to configure their browsers properly so that it uses the GZIp encoding mechanism.
All of these are good ideas- I tried putting it in a collection, and it just took too long to load, and I got an out of memory exception-same thing with a stringbuffer-I want to do William's solution, but I need to get that book to see what he's doing- what do you think if I did the following:
1. Create a startup servlet that creates the large select list and writes it to a file.
2. do a file include in my jsp to include this file.
3. Use open symphony's cache taglibs and tag up the include file so that we cache it.
William your solution sounds very good, I just need to go out and get that book. I tried using byte arrays- but it would take a bit of recoding on my part.
What do you think of my suggested solution?
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid that file include in a JSP idea still has you doing lots of String operations since it is very hard to convince a JSP to serve bytes, you need to stick to a servlet.
Bill
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok- William- I got your book for Java Performance that you suggested above- ton of good ideas therin. I coded the servlet to use byte arrays, with initializing as much as possible via the init method. Now I compared this with my servlet that used GZIP encoding, along with the print method of the printwriter and char arrays- The results were- over a 56k modem line-
1 min 55 sec's for page to download using GZIP encoding(overriding the servletoutputstream) and using the print method, using character arrays.
2 min 15 sec's for page to download using byte arrays and ServletOutputStream.
So I guess I'm going with the Gzip encoding mechanism over the byte arrays. Thanks to all of you for the help though and this book looks very cool.
[ October 30, 2002: Message edited by: Matthew Brown ]
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A question- I'm storing each of the values in an arraylist in a serializable helper class. I iterate through this arraylist in the init method,
writing it to a stringbuffer then converting to a char array[]- which is later used on the page. If the values in my arraylist are relatively static- how could I avoid the iteration of building the strings for the options/select box- I tried to store it before into the first element of the arraylist(the whole dang thing- all values and print code)- but I got an out of memory exception. Does anyone have any thoughts on this. A code example would be great.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not combine byte arrays with a zipped output stream? How much memory are you allowing for the server? Can you create the HTML needed for the list as a separate file and just read it on demand - let the operating system file cache help.
How does the 2 min 15 sec compare with delivery of an HTML file directly from a static file? (So we can figure in the 56k modem speed).
The whole optimization thing is of great interest so let us know how the project goes!!
Bill
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok- I used GZIPEncoded outputstream, and wrote them using bytes arrays via- .getBytes method on strings- and found that the page loaded in 1 min 45 seconds- a 10 second difference from using a printwriter. If the person doesn't use gzip, then it'll use the regular ServletOutputStream that I re-wrote above.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Mathew,
Any chance you can tell us how much data? Is it several MB worth of values in one drop down list? If so, perhaps your users may not like having to scroll through that many items. Maybe a "wizard" style page is in order, to break it up.
Even so, what are you returning, just the String values that go in the box? So your jsp has a loop like:
for (int i = 0, len = items.size(); i < len; i++)
{
<%
<option id="<%= i %>"><%= items.get(i).toString() %></option>
%>
}
Something like that?
By the way, if you use an ArrayList, use a for loop, not an iterator. For loops are faster, if done like how I did it above. Just a tid bit of "performance" talk, which you'll also find in that book you just bought, I have it and it is very good.
for (int i = 0; i < items.size(); i++)
{}
The above is bad because on every iteration, you are making a method call to items.size(). The better way is:
for (int i = 0, len = items.size(); i < len; i++)
{}
or
int len = items.size();
for (int i = 0; i < len; i++)
{}
The same thing occurs for an Iterator.
Iterator i = items.iterator();
while (i.hasNext())
{
..
}
The problem is, on each iteration, it makes a method call to see if it has another iteration to go. Hence, on a LARGE list, which is what you are talking about, the for loop might be quite a bit faster, resulting in a bit less download time.
Anyway, I'll await your reply to see if I can help further.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The end users want a drop down box- and actually I have a "mini" search engine on the page, where they can search for items(I used javascript regular expressions to do it).
I use an arraylist with a for loop, not an iterator, but thanks for the tip anyway.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For comparison it would be interesting to see how long it takes to serve the same content as a static page. Could you save an example of the page and report how big the total is, then time how long it takes to serve?
Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic