Use JMeter to test the performance of a database connection pool:
1. Download JMeter
2. servlet with no connection pool
Java code
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println("test 1000 add");
DBManager db=new DBManager();
db.getConnection();
db.addUser("persia", "persia");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
servlet condition with connection pooling:
Java code
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println("test 1000 add");
DBManagerByPool dbp=new DBManagerByPool();
try {
dbp.addUser("persia", "persia");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
3.JMeter Test Configuration:
(1) New thread group in new test plan by default
Thread number 5, loop 1000
(2) Set the HTTP request default value
(3) Add (Sampler inside)
2 HTTP requests corresponding to a pool with no connection
(4) Add listener--Aggregation report
(5) Run--Start
4. Test results:
Java code
Label # Samples Average Median 90% line Min Max Error% Throughput kb/sec
No connection Pool 5000 88 44 89 17 1012 0 35.57680677 7.052823998
Connection Pool 5000 50 45 68 10 236 0 35.59098836 7.194662686
Total 10000 69 45 78 10 1012 0 71.14247704 14.24239042
The average reaction time of the connectionless pool was found to be 88 milliseconds, while the average reaction time of the connection pool was 50 milliseconds.