GO效能測試:未進行任何最佳化

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

srs.go中對於GO的tcp模組,以及web伺服器martini做了初步的效能測試,沒有做任何最佳化。

TCP部分

TCP部分參考:https://github.com/winlinvip/srs.go/tree/master/research/tcp

GO作為伺服器

GO作為伺服器go build ./tcp.server.go && ./tcp.server 1 1990 4096 >/dev/nullg++ tcp.client.cpp -g -O0 -o tcp.client && ./tcp.client 1990 4096 >/dev/null ----total-cpu-usage---- -dsk/total- ---net/lo-- ---paging-- ---system--usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw   7  17  51   0   0  25|   0     0 | 680M  680M|   0     0 |2207    48k  7  15  52   0   0  26|   0     0 | 680M  680M|   0     0 |2228    48k    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND               PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                        5415 winlin    20   0  169m 2220 1404 R 100.4  0.1   0:27.56 ./tcp.server 1990 4096                                                                                         5424 winlin    20   0 11648  900  764 R 85.1  0.0   0:23.47 ./tcp.client 1990 4096   

C++作為伺服器

C++作為伺服器g++ tcp.server.cpp -g -O0 -o tcp.server && ./tcp.server 1990 4096 >/dev/null g++ tcp.client.cpp -g -O0 -o tcp.client && ./tcp.client 1990 4096 >/dev/null ----total-cpu-usage---- -dsk/total- ---net/lo-- ---paging-- ---system--usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw   6  25  44   0   0  24|   0   224k|2142M 2142M|   0     0 |2439    15k  5  23  48   0   0  23|   0     0 |2028M 2028M|   0     0 |2803    10k    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                        9758 winlin    20   0 11648  900  764 R 98.3  0.0   0:11.36 ./tcp.client 1990 4096                                                                                          9751 winlin    20   0 11648  884  752 R 71.4  0.0   0:07.85 ./tcp.server 1990 4096 

Python作為伺服器

Python作為伺服器python tcp.server.py 1990 4096 >/dev/nullg++ tcp.client.cpp -g -O0 -o tcp.client && ./tcp.client 1990 4096 >/dev/null ----total-cpu-usage---- -dsk/total- ---net/lo-- ---paging-- ---system--usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw  11  17  44   3   0  26|   0   156k|1526M 1526M|   0     0 |2215    28k 11  16  47   0   0  25|   0     0 |1482M 1482M|   0     0 |2189    26k  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                        5140 winlin    20   0  157m 5932 2824 R 100.0  0.3   2:36.01 python tcp.server.py 1990 4096                                                                                 5331 winlin    20   0 11648  900  764 R 87.3  0.0   1:02.47 ./tcp.client 1990 4096        

GO直接TCP發包時,效能比c++直接發包差。python直接發tcp包表現良好。

Web部分

Web部分參考:https://github.com/winlinvip/srs.go/tree/master/research/web

1個並發測試

用ab測試了下,1並發請求時:ab -n 100000 -c 1 http://127.0.0.1:8080/api/v3/jsonopenresty:   8851.97rps, 84%,  3MB,AB66%cherrypy:     653.12rps,   98%,17MB,AB7%go-martini:  4574.10rps,  88%,  4MB,AB35%

10個並發測試

ab -n 100000 -c 10 http://127.0.0.1:8080/api/v3/jsonopenresty:16550.72rpscherrypy: 531.28rpsgo-martini: 15737.50rps

50個並發測試

50個並發要開啟多個ab測試了,否則用戶端成為瓶頸:for((i=0;i<5;i++)); do (ab -n 100000 -c 10 http://127.0.0.1:8080/api/v3/json >req100-$i.go.txt &); doneopenresty:18514rpsgo-martini: 30954rps

100個並發測試

起5進程,每個並發20個請求:<pre name="code" class="plain">for((i=0;i<5;i++)); do (ab -n 100000 -c 20 http://127.0.0.1:8080/api/v3/json >req100-$i.go.txt &); done
openresty:29063rpsGO:43288rps


在高訪問量時,go的表現比python好很多,比openresty也要好。

go的效率和c++相比是差一些,考慮到部署和多cpu的情況可能要好,伺服器代碼也不用寫得那麼難。

go目前來看達到了高效率的python的目標。在後端裡面應該是可以考慮的,特別是一些api。

依賴包

Openresty的依賴包一大堆,部署不方便:

[winlin@dev6 web]$ ldd objs/_release/nginx/sbin/nginxlinux-vdso.so.1 =>  (0x00007fff6efcf000)libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003218400000)libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003221c00000)libm.so.6 => /lib64/libm.so.6 (0x0000003217c00000)libpcre.so.0 => /lib64/libpcre.so.0 (0x000000314ca00000)libssl.so.10 => /usr/lib64/libssl.so.10 (0x0000003ef7600000)libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x0000003ef7200000)libdl.so.2 => /lib64/libdl.so.2 (0x0000003218000000)libz.so.1 => /lib64/libz.so.1 (0x00000032ed000000)libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000328f200000)libc.so.6 => /lib64/libc.so.6 (0x0000003217800000)/lib64/ld-linux-x86-64.so.2 (0x0000003217000000)libfreebl3.so => /lib64/libfreebl3.so (0x0000003221800000)libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x0000003223c00000)libkrb5.so.3 => /lib64/libkrb5.so.3 (0x0000003224c00000)libcom_err.so.2 => /lib64/libcom_err.so.2 (0x0000003222000000)libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x0000003222800000)libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x0000003224800000)libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003222c00000)libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003219400000)libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003219000000)

GoMartini沒有額外依賴包,和python打包很像:

[winlin@dev6 web]$ ldd objs/go.martini linux-vdso.so.1 =>  (0x00007fffd25ff000)libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003218400000)libc.so.6 => /lib64/libc.so.6 (0x0000003217800000)/lib64/ld-linux-x86-64.so.2 (0x0000003217000000)

比較包的大小:

[winlin@dev6 web]$ ls -lh objs/go.martini -rwxrwxr-x 1 winlin winlin 6.4M Nov  3 14:35 objs/go.martini[winlin@dev6 web]$ ls -lh objs/_release/nginx/sbin/nginx-rwxrwxr-x 1 winlin winlin 14M Nov  3 12:05 objs/_release/nginx/sbin/nginx

GO在這方面做得都不錯。
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.