golang與node.js的http對比測試

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

註:本文對於新版本的golang並不使用,go1以後go的效能已經有了比較好的提升,具體測試見: http://www.cnblogs.com/QLeelulu/archive/2012/08/12/2635261.html

 

聽說Go是很不錯的語言,瞭解了一下,一些特性確實很不錯。

順便測試了一下http與node.js的效能對比。

go的代碼:


(註:是用8g, 8l編譯的)

node.js的代碼:

 

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.1Server Port:            8080Document Path:          /Document Length:        1 bytesConcurrency Level:      100Time taken for tests:   0.322 secondsComplete requests:      1000Failed requests:        0Write errors:           0Total transferred:      97000 bytesHTML transferred:       1000 bytesRequests 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] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        000.703Processing:     13010.52955Waiting:        13010.52955Total:          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.1Server Port:            8080Document Path:          /Document Length:        12 bytesConcurrency Level:      100Time taken for tests:   0.143 secondsComplete requests:      1000Failed requests:        0Write errors:           0Total transferred:      50000 bytesHTML transferred:       12000 bytesRequests 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] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        001.104Processing:     2136.61330Waiting:        2136.61330Total:          2146.41430

 

webbench測試結果

==** GO **==

$ webbench -t 30 -c 100 http://127.0.0.1:8080/Webbench - Simple Web Benchmark 1.5Copyright (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.5Copyright (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

求真相!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.