社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
硬件配置:
CPU:Intel(R) Xeon(R) CPU E5506 @ 2.13GHz 8核
内存:24G
软件:
Go 1.6
Node v6.9.5
测试简单输出hello world!,对比Node与Go,Node单线程,公平起见,将Go限制到单核上。
---------------------server.js-----------------
consthttp=require('http');
constserver=http.createServer((req,res)=>{
res.end('helloworld!');
});
server.listen(8087);
采样两次:
wrk -t50 -c1000 -d30s "http://192.168.1.3:8087"
Running 30s test @ http://192.168.1.3:8087
50 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 93.67ms 14.45ms 461.03ms 88.29%
Req/Sec 210.64 47.53 404.00 87.84%
298752 requests in 30.09s, 31.91MB read
Socket errors: connect 0, read 0, write 190, timeout 0
Requests/sec: 9928.87
Transfer/sec: 1.06MB
wrk -t50 -c1000 -d30s "http://192.168.1.3:8087"
Running 30s test @ http://192.168.1.3:8087
50 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 96.11ms 34.61ms 918.27ms 95.84%
Req/Sec 211.57 56.53 808.00 92.59%
306639 requests in 30.09s, 32.75MB read
Socket errors: connect 0, read 0, write 1, timeout 0
Requests/sec: 10189.06
Transfer/sec: 1.09MB
---------------------server.go------------------
packagemain
import(
"net/http"
"runtime"
"log"
"io"
)
funchandleRequest(whttp.ResponseWriter,req*http.Request){
io.WriteString(w,"helloworld!")
}
funcmain(){
runtime.GOMAXPROCS(1) //限制一个1核上
http.HandleFunc("/",handleRequest)
err:=http.ListenAndServe(":8088",nil)
iferr!=nil{
log.Fatal("ListenAndServe:",err)
}
}
采样两次:
wrk -t50 -c1000 -d30s "http://192.168.1.3:8088"
Running 30s test @ http://192.168.1.3:8088
50 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 46.24ms 14.88ms 273.98ms 86.70%
Req/Sec 433.61 101.75 1.44k 81.62%
638905 requests in 30.10s, 78.60MB read
Requests/sec: 21226.55
Transfer/sec: 2.61MB
ubuntu@ossx:~$ wrk -t50 -c1000 -d30s "http://192.168.1.3:8088"
Running 30s test @ http://192.168.1.3:8088
50 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 47.12ms 15.38ms 728.07ms 87.04%
Req/Sec 426.36 97.13 1.34k 79.68%
626564 requests in 30.10s, 77.08MB read
Requests/sec: 20816.51
Transfer/sec: 2.56MB
PS:GO的限制核是有效的,如果设置为8,效果明显不一样的,见下:
wrk -t50 -c1000 -d30s "http://192.168.1.3:8088"
Running 30s test @ http://192.168.1.3:8088
50 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 6.89ms 4.40ms 268.22ms 89.81%
Req/Sec 2.98k 618.11 18.92k 93.80%
4317520 requests in 30.10s, 531.16MB read
Requests/sec: 143437.55
Transfer/sec: 17.65MB
推荐:
微信扫码小程序使用更方便
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!