`
jiming
  • 浏览: 271526 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Netty 性能测试(与Tomcat 对比)

阅读更多
一直以来都认为 Netty 的性能会非常优秀,打算在适当的时候使用它来开发一些要求超高新能的服务。

今天兴致勃勃的写了个简单的 HTTP 服务,同样也用 tomcat 写了一个对比的 jsp 页面。结果测试下来,感觉 Netty 的性能提升并不显著。Netty 中采用的是 NIO 模式。Tomcat 采用了缺省配置。

看来采用 Netty 还要再慎重测试一下。当然这个测试结果也不是特别的严谨。这个结论不是最终结论。

Netty 测试结果

ab -n 10000 -c 10 http://192.168.1.237:8080/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.237 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        
Server Hostname:        192.168.1.237
Server Port:            8080

Document Path:          /
Document Length:        151 bytes

Concurrency Level:      10
Time taken for tests:   5.641704 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2110000 bytes
HTML transferred:       1510000 bytes
Requests per second:    1772.51 [#/sec] (mean)
Time per request:       5.642 [ms] (mean)
Time per request:       0.564 [ms] (mean, across all concurrent requests)
Transfer rate:          365.14 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.4      0      23
Processing:     1    4   2.1      4      37
Waiting:        0    3   1.9      3      26
Total:          2    4   2.7      5      38

Percentage of the requests served within a certain time (ms)
  50%      5
  66%      5
  75%      5
  80%      6
  90%      6
  95%      8
  98%     12
  99%     16
 100%     38 (longest request)


ab -k -n 10000 -c 10 http://192.168.1.237:8080/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.237 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        
Server Hostname:        192.168.1.237
Server Port:            8080

Document Path:          /
Document Length:        151 bytes

Concurrency Level:      10
Time taken for tests:   1.546421 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    10000
Total transferred:      2560768 bytes
HTML transferred:       1510453 bytes
Requests per second:    6466.54 [#/sec] (mean)
Time per request:       1.546 [ms] (mean)
Time per request:       0.155 [ms] (mean, across all concurrent requests)
Transfer rate:          1616.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       3
Processing:     0    1   1.9      1      37
Waiting:        0    0   2.1      1      37
Total:          0    1   1.9      1      38

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


Tomcat 测试结果
ab -n 10000 -c 10 http://192.168.1.237:8080/TestWeb/a.jsp
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.237 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        192.168.1.237
Server Port:            8080

Document Path:          /TestWeb/a.jsp
Document Length:        151 bytes

Concurrency Level:      10
Time taken for tests:   5.767970 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      3900000 bytes
HTML transferred:       1510000 bytes
Requests per second:    1733.71 [#/sec] (mean)
Time per request:       5.768 [ms] (mean)
Time per request:       0.577 [ms] (mean, across all concurrent requests)
Transfer rate:          660.20 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.3      1      19
Processing:     0    4   8.8      3     174
Waiting:        0    3   8.6      2     173
Total:          1    5   8.9      4     174

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      4
  75%      5
  80%      5
  90%      8
  95%     10
  98%     16
  99%     26
 100%    174 (longest request)



ab -k -n 10000 -c 10 http://192.168.1.237:8080/TestWeb/a.jsp
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.237 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        192.168.1.237
Server Port:            8080

Document Path:          /TestWeb/a.jsp
Document Length:        151 bytes

Concurrency Level:      10
Time taken for tests:   2.93494 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    9904
Total transferred:      3949520 bytes
HTML transferred:       1510000 bytes
Requests per second:    4776.70 [#/sec] (mean)
Time per request:       2.093 [ms] (mean)
Time per request:       0.209 [ms] (mean, across all concurrent requests)
Transfer rate:          1841.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       4
Processing:     0    1   7.4      1     232
Waiting:        0    1   7.4      1     232
Total:          0    1   7.4      1     232

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      2
  80%      2
  90%      3
  95%      4
  98%      8
  99%     12
 100%    232 (longest request)
[root@centos ~]# ab -k -n 10000 -c 10 http://192.168.1.237:8080/TestWeb/a.jsp
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.237 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        192.168.1.237
Server Port:            8080

Document Path:          /TestWeb/a.jsp
Document Length:        151 bytes

Concurrency Level:      10
Time taken for tests:   2.179860 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    9904
Total transferred:      3950705 bytes
HTML transferred:       1510453 bytes
Requests per second:    4587.45 [#/sec] (mean)
Time per request:       2.180 [ms] (mean)
Time per request:       0.218 [ms] (mean, across all concurrent requests)
Transfer rate:          1769.84 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       8
Processing:     0    1  10.5      1     329
Waiting:        0    1  10.5      1     329
Total:          0    1  10.5      1     329

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      2
  80%      2
  90%      3
  95%      4
  98%      7
  99%     13
 100%    329 (longest request)



分享到:
评论
4 楼 wpc009 2012-09-25  
我觉得Netty的卖点一是NIO, 二是事件驱动。 这在高并发下会有很好的表现。 博主的测试并不是高并发场景,而且也不是I/O bound! 这样Netty的特性并没有体现出来。相比Tomcat的one thread per request. Netty在高并发肯定会有不俗的表现。相反tomcat会因为频繁切换上下文而降低吞吐量。
3 楼 jiming 2010-03-30  
Profile 了一下。

发现一些 netty 的 http 核心代码有可改进的空间,修改了一下,发现能够提高 4%左右的速度。

另外发现 Netty 的 ChannelBuffer 其实还有一些可改进的方面。

代码和建议都发给 Tee 了,希望能够在下一版中看到一些改进。

深入研究后发现 Netty 的确是很不错,可以考虑在一些适合的场合使用了。
2 楼 jiming 2010-03-23  
sdh5724 写道
NIO  和阻塞访问, 你可以写个程序实验看看, 实际上, 在高压力情况下, NIO和阻塞的性能是差不多的。 但是, 在一个相对不那么高的压力下, NIO的CPU 消耗会比较高点, 但是平均响应时间也会好一点。

性能有时候不是最主要的, 轻量级的容器也是很需要的, 比如Netty。


老兄一看就是有经验的高手。

我后来也把 NIO 改成 OIO 的实现,性能要高出了10-20%左右,但是要根据应用情况调整一下 ThreadPool 的数量。这一点很符合你的说法。

我感觉对代码再精简、优化一下应该还会有性能的提升,不过暂时没时间去做了,等有时间再去试试。

我感觉这个测试中最宝贵的经验是 Netty NIO 在 keep-alive 的情况下性能相当的卓越,可以在很多的场景中利用这个特性。

1 楼 sdh5724 2010-03-22  
NIO  和阻塞访问, 你可以写个程序实验看看, 实际上, 在高压力情况下, NIO和阻塞的性能是差不多的。 但是, 在一个相对不那么高的压力下, NIO的CPU 消耗会比较高点, 但是平均响应时间也会好一点。

性能有时候不是最主要的, 轻量级的容器也是很需要的, 比如Netty。

相关推荐

Global site tag (gtag.js) - Google Analytics