go1.1beta、go1.03和nodejs的http对比测试,go1.1性能提升67%

 测试环境:

Thinkpad T60P
CPU:T2600
内存:4G
OS:Ubunt 12.04
测试版本:go1.03, go1.1beta,nodejs v0.10.3

go测试代码如下(httptest.go):

package main

import (
    "fmt"
    "log"
    "net/http"
    "runtime"
)

func main() {
    // 限制为1个CPU
    runtime.GOMAXPROCS(1)

    http.HandleFunc("/", func(w http.ResponseWriter, r  *http.Request) {
        fmt.Fprint(w, "Hello, world.")
    })

    log.Fatal(http.ListenAndServe(":8080", nil))
}

go 1.03 编译以上代码,然后运行服务器。
测试结果如下(测试两次,请求100000次,100并发)

$ ab -c 100 -n 100000 http://127.0.0.1:8080/
Concurrency Level:      100
Time taken for tests:   20.865 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      12900000 bytes
HTML transferred:       1300000 bytes
Requests per second:    4792.78 [#/sec] (mean)
Time per request:       20.865 [ms] (mean)
Time per request:       0.209 [ms] (mean, across all concurrent requests)
Transfer rate:          603.78 [Kbytes/sec] received


$ ab -c 100 -n 100000 http://127.0.0.1:8080/
Concurrency Level:      100
Time taken for tests:   21.435 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      12900000 bytes
HTML transferred:       1300000 bytes
Requests per second:    4665.31 [#/sec] (mean)
Time per request:       21.435 [ms] (mean)
Time per request:       0.214 [ms] (mean, across all concurrent requests)
Transfer rate:          587.72 [Kbytes/sec] received
go 1.1beta 编译以上代码,然后运行服务器。
测试结果如下(测试两次,请求100000次,100并发)

$ ab -c 100 -n 100000 http://127.0.0.1:8080/
Concurrency Level:      100
Time taken for tests:   12.389 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      14900000 bytes
HTML transferred:       1300000 bytes
Requests per second:    8071.55 [#/sec] (mean)
Time per request:       12.389 [ms] (mean)
Time per request:       0.124 [ms] (mean, across all concurrent requests)
Transfer rate:          1174.47 [Kbytes/sec] received

$ ab -c 100 -n 100000 http://127.0.0.1:8080/
Concurrency Level:      100
Time taken for tests:   12.937 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      14900000 bytes
HTML transferred:       1300000 bytes
Requests per second:    7729.76 [#/sec] (mean)
Time per request:       12.937 [ms] (mean)
Time per request:       0.129 [ms] (mean, across all concurrent requests)
Transfer rate:          1124.74 [Kbytes/sec] received

go1.03,go1.1beta对比结果如下:

go1.03      平均每秒处理请求4730次

go1.1beta 平均每秒处理请求7900次

go1.1beta  是 go 1.03 的1.67倍,或者说http性能提升67%

nodejs的代码如下:

var http = require('http');
http.createServer(function (req, res) {
    res.end('Hello, World.');
}).listen(8080, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8080/');

nodejs 运行以上代码,测试结果如下(测试两次,请求100000次,100并发)

$ab -c 100 -n 100000 http://127.0.0.1:8080/
Concurrency Level:      100
Time taken for tests:   21.103 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      5100000 bytes
HTML transferred:       1300000 bytes
Requests per second:    4738.60 [#/sec] (mean)
Time per request:       21.103 [ms] (mean)
Time per request:       0.211 [ms] (mean, across all concurrent requests)
Transfer rate:          236.00 [Kbytes/sec] received

$ab -c 100 -n 100000 http://127.0.0.1:8080/
Concurrency Level:      100
Time taken for tests:   21.123 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      5100000 bytes
HTML transferred:       1300000 bytes
Requests per second:    4734.12 [#/sec] (mean)
Time per request:       21.123 [ms] (mean)
Time per request:       0.211 [ms] (mean, across all concurrent requests)
Transfer rate:          235.78 [Kbytes/sec] received

结论:

nodejs比go1.03性能稍好一些(基本持平),但是低于go1.1beta.




本文来自:开源中国博客

感谢作者:玛雅牛

查看原文:go1.1beta、go1.03和nodejs的http对比测试,go1.1性能提升67%

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。