Performance of Loading JSP Pages

This section provides a tutorial example on how to measure the performance of loading a JSP page running on a Tomcat 7 server.

The next area I want test is total response time of JSP pages. To do this, I wrote the following Java program. This program is doing a single HTTP request to a specified Web page, and repeating this for many times.

/* HttpResponseTest.java
 * Copyright (c) 2002 HerongYang.com. All Rights Reserved.
 */
import java.io.*;
import java.net.*;
public class HttpResponseTest {
   public static void main(String[] args) {
      int numberOfTests = 1;
      if (args.length > 0) numberOfTests
         = Integer.valueOf(args[0]).intValue();
      long t1 = System.currentTimeMillis();
      String result = "";
      for (int nTest=1; nTest<=numberOfTests; nTest++) {
         result = test(args);
      }
      long t2 = System.currentTimeMillis();
      long t = t2 - t1;
      PrintStream out = System.out;
      out.println("Performance Information:");
      out.println("   Number of tests = " + numberOfTests);
      out.println("   Time = " + (t/1000) + " seconds.");
      out.println("Result of Last Test:");
      out.println(result);
   }
   public static String test(String[] args) {
      String path = "/index.html";
      int port = 80;
      String host = "localhost";
      if (args.length > 1) path = args[1];
      if (args.length > 2) port
         = Integer.valueOf(args[2]).intValue();
      if (args.length > 3) host = args[3];
      String result = "";
      try {
         Socket c = new Socket(host,port);
         BufferedWriter w = new BufferedWriter(new OutputStreamWriter(
            c.getOutputStream()));
         BufferedReader r = new BufferedReader(new InputStreamReader(
            c.getInputStream()));
         String m = "GET "+path;
         w.write(m,0,m.length());
         w.newLine();
         w.flush();
         while ((m=r.readLine())!= null) {
            result = result + m + "\n";
         }
         w.close();
         r.close();
         c.close();
      } catch (IOException e) {
         System.err.println(e.toString());
      }
      return result;
   }
}

Now compile this program and try it with the following "Hello" JSP page, hello.jsp:

<html><body>
<% out.println("Hello world!"); %>
</body></html>

You will get something similar to this:

herong> java -cp . HttpResponseTest 1 /hello.jsp 8080
Performance Information:
   Number of tests = 1
   Time = 1 seconds.

Result of Last Test:
<html><body>
Hello world!

</body></html>

I repeated the tests by changing the controlling parameters. The following table shows the results comparing with similar tests I did with other technologies on my old computer in 2006:

        Number     Debug    Time
Cases   of Tests   Mode    (Sec)   Note

1.      1000       No          2   Static text with IIS 5.0
2.      2000       No          4   Static text with IIS 5.0
3.      1000       No          6   ASP page with IIS 5.0
4.      2000       No         11   ASP page with IIS 5.0
5.      1000       ?           7   Static text with Tomcat 4.1.18
6.      2000       ?          15   Static text with Tomcat 4.1.18
7.      1000       ?           8   JSP page with Tomcat 4.1.18
8.      2000       ?          16   JSP page with Tomcat 4.1.18

Conclusion:

On my new computer in 2012, of course the sample JSP runs much faster. Execution time reduced from 8 seconds to 1 second for the "1000" test.

        Number     Debug    Time
Cases   of Tests   Mode    (Sec)   Note

1.      1000       ?           1   JSP page with Tomcat 7.0.32
2.      10000      ?           4   JSP page with Tomcat 7.0.32
2.      100000     ?          35   JSP page with Tomcat 7.0.32

On my second new computer 2018, the sample JSP runs slower than my last old computer! Execution times doubled for both "10000" and "100000" tests. I think my Tomcat 9 server needs some performance tuning.

        Number     Debug    Time
Cases   of Tests   Mode    (Sec)   Note

1.      1000       ?           1   JSP page with Tomcat 9.0.12
2.      10000      ?          10   JSP page with Tomcat 9.0.12
3.      100000     ?          93   JSP page with Tomcat 9.0.12

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

Performance of JSP Pages

 Performance of Calculating Prime Numbers

Performance of Loading JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Using Tomcat on CentOS Systems

 Using Tomcat on macOS Systems

 Connecting to SQL Server from Servlet

 Developing Web Applications with Servlet

 Archived Tutorials

 References

 Full Version in PDF/EPUB