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个请求:
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:29063rps
GO:43288rps
在高访问量时,go的表现比python好很多,比openresty也要好。
go的效率和c++相比是差一些,考虑到部署和多cpu的情况可能要好,服务器代码也不用写得那么难。
go目前来看达到了高效率的python的目标。在后端里面应该是可以考虑的,特别是一些api。
Web+Mysql部分
Web后端访问mysql数据库部分,参考:https://github.com/winlinvip/srs.go/tree/master/research/web.mysql
具体脚本参考https://github.com/winlinvip/srs.go/tree/master/research/web.mysql/ab-benchmark目录的脚本
1000条记录,select前10条,并发请求1
1000条记录,select前10条,并发请求1:
openresty:1750.54rps
go-martini: 910.32rps
cherrypy: 303.29rps
1000条记录,select前10条,并发请求10
1000条记录,select前10条,并发请求10:
openresty:7911.45rps
go-martini: 6483.20rps
cherrypy: 254.13rps
1000条记录,select前10条,并发请求20,5进程
1000条记录,select前10条,并发请求20,5进程:
openresty:12526rps
go-martini: 8724rps
10万条记录,select前10条,并发请求1
10万条记录,select前10条,并发请求1
openresty:1741.09rps
go-martini: 912.17rps
cherrypy: 304.23rps
10万条记录,select前10条,并发请求10
10万条记录,select前10条,并发请求10
openresty: 6890.48rps
go-margini: 6510.01rps
cherrypy: 251.29rps
10万条记录,select前10条,并发请求20,5进程
10万条记录,select前10条,并发请求20,5进程
openresty: 12208rps
go-martini: 8728rps
100万条记录,select前10条,并发请求1
100万条记录,select前10条,并发请求1
openresty: 1730.30rps
go-martini: 911.85rps
cherrypy: 304.16rps
100万条记录,select前10条,并发请求10
100万条记录,select前10条,并发请求10
openresty: 6727.13rps
go-martini: 6633.57rps
cherrypy: 254.27rps
100万条记录,select前10条,并发请求20,5进程
100万条记录,select前10条,并发请求20,5进程
openresty: 12386rps
go-martini: 7004rps
可见带上数据库后,openresty的性能基本上是go的两倍,但是都比cherrypy高很多。
依赖包
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在这方面做得都不错。