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/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 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/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 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/json openresty: 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/json openresty:16550.72rps cherrypy: 531.28rps go-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 &); done openresty:18514rps go-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 &); doneopenresty:29063rpsGO:43288rps 在高访问量时,go的表现比python好很多,比openresty也要好。
go的效率和c++相比是差一些,考虑到部署和多cpu的情况可能要好,服务器代码也不用写得那么难。
go目前来看达到了高效率的python的目标。在后端里面应该是可以考虑的,特别是一些api。
依赖包
Openresty的依赖包一大堆,部署不方便:
[winlin@dev6 web]$ ldd objs/_release/nginx/sbin/nginx linux-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在这方面做得都不错。
有疑问加站长微信联系(非本文作者)