?
Solved

Performance: Download/display a JSP vs HTML

Posted on 2005-04-29
14
Medium Priority
?
310 Views
Last Modified: 2010-04-01
Hi Experts,

We have a JSP app and one of our page that displays a list of product info from the database is really long and it is taking too much time (7 seconds) to display. We did some diagnosis and found out that the bottle neck is not database/server code. Rather, it starts from the server renders the JSP then browser downloads it and displays it. To test that theory, we saved that page on the browser as a seperate HTML document and put it back on the server. Now when we try to access that HTML on the server it came  back less than 2 seconds. The file size is about 400K so I think we've got pretty decent network speed. The problem seems to be pointing to the production server that is sitting 30 miles away from our office rendering the JSP. However, the same JSP shows up in 2 seconds when it is on our development server in the office.

I will really appreciate if anyone have any insight to our problem. I am going to assign 500 points for this question, hope this is a good incentive for all experts here.

Thanks

Stephen
0
Comment
Question by:autoknowledge
  • 6
  • 2
  • 2
  • +3
14 Comments
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 240 total points
ID: 13895466
Although it is a workaround rather than a solution, but why isn't that table split in separate pages? If it needs to show all products due to download needs or stuff, you'd better generate a CSV..

-r-
0
 

Author Comment

by:autoknowledge
ID: 13895664
Splitting the list in multiple pages is an option, we actually used to do it that way. But for usesability reason we swicted to have it displayed on a single page.

Downloading here I meant the browser has to download the page from the server (30 miles away) before opening it. Sorry for the confusion.

Thanks for the input, I will consolidate all inputs from everyone and will award points after that.

Stephen
0
 

Author Comment

by:autoknowledge
ID: 13895701
Downloading here I meant the browser has to download the page from the server (30 miles away) before DISPLAYING it
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 240 total points
ID: 13896574
Hi Stephen,

Well, I do not know whether it would be useful for you or not. If you use JDBC, make sure that you use PreparedStatement since it is much efficient and faster. Second, you should consider to use cache to save your data so instead of connecting to DB again, you can get the data from your cache. Anyway, just input :).

Regards
Dave
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 13896586
Hi,

If you use cache, you will be slow when downloading the data by first time but the next time, it would be faster.

Regards
Dave
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 240 total points
ID: 13896736
if its coming within 2 seconds in development environment than its more of a network latency issue than code..
what kind of connection you have got between the server and the browser?? 400k in 7 seconds is close to 54KBPS speed which is the max possible speed on dial up..
so that means your system is running to its full capacity and there is really nothing much you can change apart from splitting your page...
or may be first show the page without all the data and then populate the data upon user request ( on the selection of a drop down or a radio button or on a submit etc...)
0
 

Author Comment

by:autoknowledge
ID: 13897564
First of all, thanks for the replies. All are nice thoughts.

Yes we are using cache already. First time loading the page is much slower than 2nd or 3rd time, but even for the non-first time load it takes 7 seconds, which is too slow.

Okay let me clarify this a little bit.
It takes 2 seconds to load up the JSP from the development environment (local).
It takes 7 seconds to load up the JSP from the production server (30 miles away --> network issue?).
It takes 2 seconds to load up the HTML from the production server. This HTML is obtained by doing a "save as" on the IE to "full HTML document" when we see the JSP page on the browser. We put that 400K HTML file on the server just to test the network speed because I was trying to see whether rendering JSP or network latency is the main driver for that.

The result came back was inconclusive because the 2 seconds for HTML may suggest that network speed is decent, while the 2 seconds for JSP in development environment may suggest it's the network, and server rendering is fast (production server is a much better machine than our development).

Thanks

Stephen
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13897586
okay your result suggests that your jsp is taking too much of time to connect to the database while its on the production server ( may be because production database is much larger than your test database, or the database and production server connection is slow..)
if your HTML from production server is coming back in 2 seconds then its not your network... it has to be your database access..
0
 

Author Comment

by:autoknowledge
ID: 13897620
Since we are caching the data, there is no database connection calls from the 2nd time on
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 540 total points
ID: 13899022
>>First time loading the page is much slower than 2nd or 3rd time
This is due to the page bring compiled and it fairly standard.

>>(production server is a much better machine than our development).
The difference between the local server and the production server is going to be either network issues as you mention, or hardware. If the local server has a faster CPU or more importantly more RAM (or has less load on it) you will see a disparity in the time it takes to generate the code.

The best way to find out would be to find out the time taken to generate the page, which requires you to put timing calls at the top and bottom of the JSP and and also create a timing request, so call the page via an HttpUrlConnection so that you can see the time actually taken to transmit hte page across the network. Here's a conveniece method for yuo to time.

<code>
     public static String getURL( final String pURL ){
          StringBuffer sb = new StringBuffer();
          try {
               URL u = new URL( pURL );
               HttpURLConnection huc = (HttpURLConnection) u.openConnection();
               huc.setRequestMethod( GET );
               huc.connect();
               BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));

               int b = 0;
               while((b = br.read()) != -1) {
                    sb.append((char)b);
               }
               br.close();
               // disconnect HttpURLConnection
               huc.disconnect() ;
          }
          catch (IOException e){
               return "Unable to open connection: " + e.getMessage();
          }
          return sb.toString();
     }
</code>

0
 
LVL 11

Assisted Solution

by:Manish
Manish earned 240 total points
ID: 13907104
U can precompile ur jsp so that first request will not take much time.
like in web.xml u can load ur jsp on start up of server

<servlet>
    <servlet-name>login</servlet-name>
    <jsp-file>/login.jsp</jsp-file>
    <load-on-startup>1</load-on-startup>
  </servlet>


0
 

Author Comment

by:autoknowledge
ID: 13909741
bloodredsun,

The code you post here is a can measure how fast our server generate the page? Are you suggesting me to create a JSP that contains that code and put the timing function call to wrap around the getURL(final String pURL). Could you explain how does this code help diagnose my problem a little bit?

Thanks

Stephen
0
 

Author Comment

by:autoknowledge
ID: 13909765
karanw,

Thanks for the suggestion, tried that. It speeds up the first time, but not subsequent accesses.

Thanks

Stephen
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13910014
The method allos you to create either an app or a JSP where you can measure the start and stop time of the request.

long t0 = System.currentMillis();
String returnedJSP = getUrl("http://yourhost.com/yourapp/index.jsp");
long t1 = System.currentMillis();
System.out.println("request (network and processing) took: " + (t1-t0) + "ms") ;
System.out.println("JSP took: " +returnedJSP + "ms") ;

This allows you to look at the time taken over the network. If you create a JSP that ouputs the processing time as it's HTML than you can also look at just the processing time.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question