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

玛雅牛 · · 2519 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

 测试环境:

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%

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2519 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传