论坛首页 Java企业应用论坛

关于jetty与tomcat一些性能的研究

浏览 21694 次
精华帖 (0) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-04-06  
现在我有一个servlet的url为/servlet/TestRuning
其中关键代码是
PrintWriter out = response.getWriter();
		String aStr = request.getParameter("a");
		String bStr = request.getParameter("b");
		
		int a = 100;
		int b = 100;
		
		try{
			a = Integer.parseInt(aStr);
			b = Integer.parseInt(bStr);
		}catch(Exception excep){
			System.err.println("err:" + excep.getMessage());
		}
		int sum = 0;
		long s = System.currentTimeMillis();
		for(int i = 0; i < a; ++i){
			for(int ii = 0; ii < b; ++ii){
				sum = a / b;
			}
		}
		long e = System.currentTimeMillis();
		long d = e - s;
		out.println( d );
		
		
		out.flush();
		out.close();

这个代码只是两个循环,其中只是作一些除法运算操作。
然后计算时间,并输出给客户端。
此时我将这个应用布署在jetty与tomcat两个服务器中
这两个服务程序都是使用了默认的配置。

在启动程序时,我先使用两个相同的jre。
wapproxy@ubuntu:~$ ps -ef | grep java
wapproxy  2076     1  1 11:28 ?        00:00:03 /usr/lib/jvm/java-6-openjdk/jre/bin/java -Djetty.home=/home/wapproxy/jetty -Djava.io.tmpdir=/tmp -jar /home/wapproxy/jetty/start.jar /home/wapproxy/jetty/etc/jetty-logging.xml /home/wapproxy/jetty/etc/jetty.xml
wapproxy  2185  1398  8 11:30 pts/0    00:00:02 /usr/lib/jvm/java-6-openjdk/jre/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/home/wapproxy/Tomcat/conf/logging.properties -Djava.endorsed.dirs=/home/wapproxy/Tomcat/endorsed -classpath :/home/wapproxy/Tomcat/bin/bootstrap.jar -Dcatalina.base=/home/wapproxy/Tomcat -Dcatalina.home=/home/wapproxy/Tomcat -Djava.io.tmpdir=/home/wapproxy/Tomcat/temp org.apache.catalina.startup.Bootstrap start
wapproxy  2329  2309  0 11:31 pts/1    00:00:00 grep --color=auto java

确认一次,在这两个应用中我是布署了相同的应用程序,应用名为jt_jt。
其中tomcat的端口为8888
jetty的端口为8080

我使用ab进行压力测试
Server Software:        Jetty(6.1.22)
Server Hostname:        172.31.36.158
Server Port:            8080

Document Path:          /jt_jt/servlet/TestRuning?a=100000&b=100000
Document Length:        2 bytes

Concurrency Level:      1
Time taken for tests:   8.715 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      445000 bytes
HTML transferred:       10000 bytes
Requests per second:    573.72 [#/sec] (mean)
Time per request:       1.743 [ms] (mean)
Time per request:       1.743 [ms] (mean, across all concurrent requests)
Transfer rate:          49.86 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.1      0       5
Processing:     0    1   7.1      0      50
Waiting:        0    1   7.1      0      50
Total:          0    2   7.2      0      50

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      5
  95%      5
  98%     45
  99%     50
 100%     50 (longest request)

以上是jetty的,下边是tomcat的
Server Software:        Apache-Coyote/1.1
Server Hostname:        172.31.36.158
Server Port:            8888

Document Path:          /jt_jt/servlet/TestRuning?a=100000&b=100000
Document Length:        3 bytes

Concurrency Level:      1
Time taken for tests:   4.070 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      650000 bytes
HTML transferred:       15000 bytes
Requests per second:    1228.50 [#/sec] (mean)
Time per request:       0.814 [ms] (mean)
Time per request:       0.814 [ms] (mean, across all concurrent requests)
Transfer rate:          155.96 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.2      0       5
Processing:     0    0   1.7      0      45
Waiting:        0    0   1.7      0      45
Total:          0    1   2.1      0      45

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      5
  95%      5
  98%      5
  99%      5
 100%     45 (longest request)

两次测试的并发量我设成了1,也就是线程池的模式对测试结果影响不大。
关键数据如下
jetty 8080 Requests per second:    573.72 [#/sec] (mean)
tomcat 8888  Requests per second:    1228.50 [#/sec] (mean)
基本相差一倍之多。
为什么会有这个问题呢?

也许你想看看输入内容是多少
用浏览器输入单次请求http://172.31.36.158:8888/jt_jt/servlet/TestRuning?a=10000000&b=100000000
返回结果为零。

这样是不是可以证明jetty比tomcat是慢一倍呢?
如果可以证明,为什么jetty是慢过tomcat那么多呢?
   发表时间:2010-04-06  
现在改成输出一定量的字节数进行测试
新的servlet servlet/MkLen?len=字节数
关键代码
String lenStr = request.getParameter("len");
		int len = 100;
		try{
			len = Integer.parseInt(lenStr);
		}catch(Exception excep){
			System.err.println("err:" + excep.getMessage());
		}
		for(int i = 0; i < len; ++i){
			out.print("_");
		}

然后是我的压力测试输出,当然两个jre是一样的。
jetty测试结果如下
Server Software:        Jetty(6.1.22)
Server Hostname:        172.31.36.158
Server Port:            8080

Document Path:          /jt_jt/servlet/MkLen?len=1000
Document Length:        1000 bytes

Concurrency Level:      1
Time taken for tests:   9.200 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      5435000 bytes
HTML transferred:       5000000 bytes
Requests per second:    543.48 [#/sec] (mean)
Time per request:       1.840 [ms] (mean)
Time per request:       1.840 [ms] (mean, across all concurrent requests)
Transfer rate:          576.91 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.2      0       5
Processing:     0    1   5.8      0      50
Waiting:        0    1   5.8      0      50
Total:          0    2   5.9      0      55

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      5
  90%      5
  95%      5
  98%      5
  99%     50
 100%     55 (longest request)

tomcat服务测试结果如下
Server Software:        Apache-Coyote/1.1
Server Hostname:        172.31.36.158
Server Port:            8888

Document Path:          /jt_jt/servlet/MkLen?len=1000
Document Length:        1000 bytes

Concurrency Level:      1
Time taken for tests:   5.860 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      5635000 bytes
HTML transferred:       5000000 bytes
Requests per second:    853.24 [#/sec] (mean)
Time per request:       1.172 [ms] (mean)
Time per request:       1.172 [ms] (mean, across all concurrent requests)
Transfer rate:          939.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.3      0       5
Processing:     0    1   2.0      0      25
Waiting:        0    1   1.9      0      25
Total:          0    1   2.2      0      25

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      5
  90%      5
  95%      5
  98%      5
  99%      5

关键结果:
jetty
Total transferred:      5435000 bytes
HTML transferred:       5000000 bytes
Requests per second:    543.48 [#/sec] (mean)

tomcat
Total transferred:      5635000 bytes
HTML transferred:       5000000 bytes
Requests per second:    853.24 [#/sec] (mean)


依然是tomcat性能占优。
0 请登录后投票
   发表时间:2010-04-06  
这是....?  未完待续?
0 请登录后投票
   发表时间:2010-04-06  
结论初步为使用Tomcat性能比jetty较好
0 请登录后投票
   发表时间:2010-04-06   最后修改:2010-04-06
如果jetty比tomcat性能好那么多,google应该用使用tomcat作为它的appenginee的servlet container,去跟google说说
0 请登录后投票
   发表时间:2010-04-06  
hzh0725 写道
如果jetty比tomcat性能好那么多,google应该用使用tomcat作为它的appenginee的servlet container,去跟google说说

其实我并敢大胆说tomcat性能比jetty,可是现在事实如此,也许是需要配置什么地方,才可以发挥jetty性能。
所以需要请教一下大家。哈哈
0 请登录后投票
   发表时间:2010-04-07  
Tomcat默认是用老的IO库,要在Server.xml打开NIO再测,Jetty默认就NIO了
0 请登录后投票
   发表时间:2010-04-07  
且不说性能,最近才开始接触到jetty,把一个在tomcat运行良好的项目部署到jetty中,直接启动报错,虽还未查明原因,但是主观上就已经对jetty有抵触了。。。
0 请登录后投票
   发表时间:2010-04-07  
Google App 现在对J2EE的支持还是初级阶段,所以还没必要上TOMCAT。
0 请登录后投票
   发表时间:2010-04-07  
得出的数据太单一了。没有很大的参考价值。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics