golang与node.js的http对比测试

注:本文对于新版本的golang并不使用,go1以后go的性能已经有了比较好的提升,具体测试见: http://www.cnblogs.com/QLeelulu/archive/2012/08/12/2635261.html

 

听说Go是很不错的语言,了解了一下,一些特性确实很不错。

顺便测试了一下http与node.js的性能对比。

go的代码:

image
(注:是用8g, 8l编译的)

node.js的代码:

image

 

ab测试结果:

==** GO **==

复制代码
$ ab -c 100 -n 1000 http://127.0.0.1:8080/
This is ApacheBench, Version 2.3<$Revision: 655654$>

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /
Document Length:        1 bytes

Concurrency Level:      100
Time taken for tests:   0.322 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      97000 bytes
HTML transferred:       1000 bytes
Requests per second:    3105.62 [#/sec] (mean)
Time per request:       32.200 [ms] (mean)
Time per request:       0.322 [ms] (mean, across all concurrent requests)
Transfer rate:          294.18 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        000.703
Processing:     13010.52955
Waiting:        13010.52955
Total:          43010.12955
复制代码

==** Node.js **==

复制代码
$ ab -c 100 -n 1000 http://127.0.0.1:8080/
This is ApacheBench, Version 2.3<$Revision: 655654$>

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   0.143 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      50000 bytes
HTML transferred:       12000 bytes
Requests per second:    6993.50 [#/sec] (mean)
Time per request:       14.299 [ms] (mean)
Time per request:       0.143 [ms] (mean, across all concurrent requests)
Transfer rate:          341.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        001.104
Processing:     2136.61330
Waiting:        2136.61330
Total:          2146.41430
复制代码

 

webbench测试结果

==** GO **==

复制代码
$ webbench -t 30 -c 100 http://127.0.0.1:8080/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://127.0.0.1:8080/
100 clients, running 30 sec.

Speed=146934 pages/min, 262032 bytes/sec.
Requests: 73467 susceed,0 failed.
复制代码

==** Node.js **==

复制代码
$ webbench -t 30 -c 100 http://127.0.0.1:8080/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://127.0.0.1:8080/
100 clients, running 30 sec.

Speed=485128 pages/min, 404273 bytes/sec.
Requests: 242564 susceed,0 failed.
复制代码

从测试结果来看,node.js的HTTP SERVER性能是Go的两倍还多,而且让我比较郁闷的是,在用webbench进行测试的时候,可以看到go是用了我的笔记本上的四个核的CPU的,而node.js当然是只跑在一个核上,而Go居然还比node.js慢这么多。

然后我google,就看到:golang helloworld 45% slower than node.js

求真相!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值