使用JMeter测试一下有无数据库连接池的性能:
1.下载JMeter
2.无连接池的servlet
Java代码
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情况:
Java代码
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测试配置:
(1)默认新建的测试计划里面新建线程组
线程数5,循环1000
(2)设置HTTP请求默认值
(3)添加(sampler里面)2个HTTP请求分别对应有无连接池
(4)添加监听器--聚合报告
(5)运行--启动
4.测试结果:
Java代码
- Label # Samples Average Median 90% Line Min Max Error % Throughput KB/sec
- 无连接池池 5000 88 44 89 17 1012 0 35.57680677 7.052823998
- 连接池 5000 50 45 68 10 236 0 35.59098836 7.194662686
- 总体 10000 69 45 78 10 1012 0 71.14247704 14.24239042
|
发现无连接池的平均反应时间为88毫秒,而有连接池的平均反应时间为50毫秒。