php 原生,swoole, golang 针对上传excel性能对比

先说结论吧,php5.6的 情况下,php 原生速度稳定性略微优于swoole,相差不大,php7的性能 在这种场景下要 提升接近一倍的性能,在php7的时候,swoole 表现比php原生 大约有20%的提升,极限情况下,php 原生要比swoole并发略高,但是有一定程度的超时。
golang的性能,在100行excel的情况下,并发是220s,cpu 20%, 是当时的php 的10倍左右,瓶颈在于数据库,数据库服务器的cpu达到60%,250个插入进程并发执行, 如果进一步优化插入的sql,可以达到更高。

压测工具使用的是Jmeter.

压测的接口如下
staff/upload-staff-excel(swoole 实现)
excel/upload-staff-excel(php 原生)
代码地址:http://doujm@jdb-dev.com/doujm/enterprise-swoole.git

场景描述: 针对excel 上传并解析,插入数据库,并返回响应的数据,swoole 和php 原生代码逻辑完全相同.

第一步 ,excel 三行 , 100线程下压测

Swoole   : cpu 稳定在98%左右,QPS 为29/s, 响应时间,为3S – 3.1S左右, 平均 1.6%的超时,

summary + 345 in 14s = 25.2/s Avg: 3262 Min: 2 Max: 5648 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary + 901 in 30s = 30.0/s Avg: 3014 Min: 1 Max: 5554 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 1246 in 44s = 28.5/s Avg: 3082 Min: 1 Max: 5648 Err: 0 (0.00%)
summary + 872 in 30s = 29.0/s Avg: 2712 Min: 1 Max: 60002 Err: 2 (0.23%) Active: 100 Started: 100 Finished: 0
summary = 2118 in 74s = 28.7/s Avg: 2930 Min: 1 Max: 60002 Err: 2 (0.09%)
summary + 848 in 30s = 28.3/s Avg: 3156 Min: 1 Max: 60001 Err: 14 (1.65%) Active: 100 Started: 100 Finished: 0
summary = 2966 in 104s = 28.6/s Avg: 2995 Min: 1 Max: 60002 Err: 16 (0.54%)
summary + 873 in 30s = 29.1/s Avg: 3175 Min: 0 Max: 64368 Err: 21 (2.41%) Active: 100 Started: 100 Finished: 0
summary = 3839 in 134s = 28.7/s Avg: 3036 Min: 0 Max: 64368 Err: 37 (0.96%)
summary + 895 in 30s = 29.8/s Avg: 3701 Min: 0 Max: 62674 Err: 27 (3.02%) Active: 100 Started: 100 Finished: 0
summary = 4734 in 164s = 28.9/s Avg: 3161 Min: 0 Max: 64368 Err: 64 (1.35%)

php原生 :cpu 稳定在97%左右,QPS 29/s ,响应时间为3.1-3.2S左右, 平均 0%的超时

 

summary + 272 in 10.5s = 25.9/s Avg: 3225 Min: 2693 Max: 4230 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary + 906 in 30s = 30.2/s Avg: 3313 Min: 3004 Max: 4229 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 1178 in 40.5s = 29.1/s Avg: 3293 Min: 2693 Max: 4230 Err: 0 (0.00%)
summary + 905 in 30.1s = 30.1/s Avg: 3258 Min: 2731 Max: 3933 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 2083 in 71s = 29.5/s Avg: 3278 Min: 2693 Max: 4230 Err: 0 (0.00%)
summary + 924 in 30s = 30.9/s Avg: 3251 Min: 2646 Max: 4575 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 3007 in 100.5s = 29.9/s Avg: 3270 Min: 2646 Max: 4575 Err: 0 (0.00%)
summary + 923 in 30s = 30.8/s Avg: 3257 Min: 2635 Max: 4250 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 3930 in 130s = 30.1/s Avg: 3267 Min: 2635 Max: 4575 Err: 0 (0.00%)

 

第二步 ,excel 100行 , 100线程下压测

1. Swoole:cpu 稳定在97%左右, QPS 为25/s , 响应时间,为3.4-4.1S左右, 平均 2.8%的超时

summary = 976 in 43.1s = 22.7/s Avg: 3340 Min: 2 Max: 5409 Err: 0 (0.00%)
summary + 760 in 30.1s = 25.3/s Avg: 2704 Min: 0 Max: 64820 Err: 12 (1.58%) Active: 100 Started: 100 Finished: 0
summary = 1736 in 73.1s = 23.7/s Avg: 3062 Min: 0 Max: 64820 Err: 12 (0.69%)
summary + 760 in 30s = 25.4/s Avg: 4259 Min: 0 Max: 65179 Err: 33 (4.34%) Active: 100 Started: 100 Finished: 0
summary = 2496 in 103s = 24.2/s Avg: 3426 Min: 0 Max: 65179 Err: 45 (1.80%)
summary + 768 in 30s = 25.6/s Avg: 3571 Min: 0 Max: 62734 Err: 26 (3.39%) Active: 100 Started: 100 Finished: 0
summary = 3264 in 133s = 24.5/s Avg: 3460 Min: 0 Max: 65179 Err: 71 (2.18%)
summary + 762 in 30s = 25.4/s Avg: 3924 Min: 0 Max: 62463 Err: 32 (4.20%) Active: 100 Started: 100 Finished: 0
summary = 4026 in 163s = 24.7/s Avg: 3548 Min: 0 Max: 65179 Err: 103 (2.56%)
summary + 769 in 30s = 25.6/s Avg: 4131 Min: 0 Max: 62634 Err: 33 (4.29%) Active: 100 Started: 100 Finished: 0
summary = 4795 in 193s = 24.8/s Avg: 3641 Min: 0 Max: 65179 Err: 136 (2.84%)

2. php原生 : 平均稳定在96%,QPS为28/s, 响应时间为3.4S,超时为0%。

summary + 1 in 2.2s = 0.5/s Avg: 1898 Min: 1898 Max: 1898 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary + 780 in 28s = 28.3/s Avg: 3458 Min: 1965 Max: 4824 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 781 in 30s = 26.2/s Avg: 3456 Min: 1898 Max: 4824 Err: 0 (0.00%)
summary + 851 in 29.3s = 29.0/s Avg: 3478 Min: 3140 Max: 4707 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 1632 in 59.1s = 27.6/s Avg: 3468 Min: 1898 Max: 4824 Err: 0 (0.00%)
summary + 860 in 30s = 28.8/s Avg: 3474 Min: 3104 Max: 4753 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 2492 in 89s = 28.0/s Avg: 3470 Min: 1898 Max: 4824 Err: 0 (0.00%)
summary + 869 in 30s = 29.0/s Avg: 3464 Min: 3135 Max: 5078 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 3361 in 119s = 28.2/s Avg: 3468 Min: 1898 Max: 5078 Err: 0 (0.00%)

3.php7 swoole 表现:cpu 消耗 40%左右,某一个cpu稳定在96%左右,

summary +    255 in     9s =   29.6/s Avg:  2534 Min:   400 Max:  3368 Err:     0 (0.00%) Active: 100 Started: 100 Finished: 0
summary +    920 in    30s =   30.7/s Avg:  3273 Min:  2867 Max:  3634 Err:     0 (0.00%) Active: 100 Started: 100 Finished: 0
summary =   1175 in    39s =   30.5/s Avg:  3112 Min:   400 Max:  3634 Err:     0 (0.00%)
summary +    928 in    30s =   30.9/s Avg:  3208 Min:  2784 Max:  3690 Err:     0 (0.00%) Active: 100 Started: 100 Finished: 0
summary =   2103 in    69s =   30.7/s Avg:  3155 Min:   400 Max:  3690 Err:     0 (0.00%)

第三步 ,excel 500行 , 100线程下压测

Swoole:cpu 稳定在97%左右,QPS 为16/s, 响应时间,前期为4S左右,后期5-6S左右,共发送请求3074个,超时119个,  平均 3.8%的超时

 

summary = 458 in 28s = 16.4/s Avg: 4353 Min: 2 Max: 7162 Err: 0 (0.00%)
summary + 497 in 30.2s = 16.5/s Avg: 3647 Min: 2 Max: 7369 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 955 in 58.1s = 16.4/s Avg: 3985 Min: 2 Max: 7369 Err: 0 (0.00%)
summary + 505 in 30s = 17.0/s Avg: 5989 Min: 0 Max: 65247 Err: 29 (5.74%) Active: 100 Started: 100 Finished: 0
summary = 1460 in 88s = 16.6/s Avg: 4678 Min: 0 Max: 65247 Err: 29 (1.99%)
summary + 503 in 30s = 16.8/s Avg: 6016 Min: 0 Max: 65109 Err: 30 (5.96%) Active: 100 Started: 100 Finished: 0

php原生 : 平均稳定在96%,QPS 为20/s, 响应时间为4.5S,超时为0%。

summary + 495 in 25.4s = 19.5/s Avg: 4500 Min: 2497 Max: 6831 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary + 670 in 30s = 22.5/s Avg: 4542 Min: 3041 Max: 6182 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 1165 in 55.2s = 21.1/s Avg: 4524 Min: 2497 Max: 6831 Err: 0 (0.00%)
summary + 653 in 30s = 21.8/s Avg: 4488 Min: 3339 Max: 6288 Err: 0 (0.00%) Active: 100 Started: 100 Finished: 0
summary = 1818 in 85.2s = 21.3/s Avg: 4511 Min: 2497 Max: 6831 Err: 0 (0.00%)

 
golang 的压测结果,cpu在20%左右,qps 220/s,左右,响应1100ms,瓶颈在于数据库插入速度,

summary +   5520 in    25s =  220.7/s Avg:  1119 Min:   524 Max:  1501 Err:     0 (0.00%) Active: 250 Started: 250 Finished: 0
summary =   5521 in    26s =  213.0/s Avg:  1119 Min:   524 Max:  1501 Err:     0 (0.00%)
summary +   6675 in    30s =  222.5/s Avg:  1123 Min:   860 Max:  1411 Err:     0 (0.00%) Active: 250 Started: 250 Finished: 0
summary =  12196 in    56s =  218.1/s Avg:  1121 Min:   524 Max:  1501 Err:     0 (0.00%)

第四步 ,excel 500行 , 3线程下压测 ,

swoole : CPU负载 不超过0.5%, 前期响应400ms, 后期12342ms也有,请求608次,21次超时 很不稳定

summary +     96 in    14s =    6.8/s Avg:   418 Min:   320 Max:   540 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary +    109 in  60.1s =    1.8/s Avg:   995 Min:   359 Max: 60030 Err:     1 (0.92%) Active: 3 Started: 3 Finished: 0
summary =    205 in  74.1s =    2.8/s Avg:   724 Min:   320 Max: 60030 Err:     1 (0.49%)
summary +     28 in    30s =    0.9/s Avg:  4740 Min:   350 Max: 60016 Err:     2 (7.14%) Active: 3 Started: 3 Finished: 0
summary =    233 in   104s =    2.2/s Avg:  1207 Min:   320 Max: 60030 Err:     3 (1.29%)
summary +     90 in    30s =    3.0/s Avg:   480 Min:   346 Max:   614 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =    323 in   134s =    2.4/s Avg:  1004 Min:   320 Max: 60030 Err:     3 (0.93%)
summary +     29 in  61.2s =    0.5/s Avg:  6615 Min:   329 Max: 60043 Err:     3 (10.34%) Active: 3 Started: 3 Finished: 0
summary =    352 in   195s =    1.8/s Avg:  1467 Min:   320 Max: 60043 Err:     6 (1.70%)

php 原生:CPU负载不超过0.5%,响应 423毫秒很稳定, 没有超时

summary +    105 in  15.4s =    6.8/s Avg:   424 Min:   345 Max:   561 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary +    213 in  30.2s =    7.1/s Avg:   423 Min:   326 Max:   668 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =    318 in    46s =    7.0/s Avg:   423 Min:   326 Max:   668 Err:     0 (0.00%)
summary +    211 in    30s =    7.1/s Avg:   425 Min:   332 Max:   729 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =    529 in  75.5s =    7.0/s Avg:   424 Min:   326 Max:   729 Err:     0 (0.00%)
summary +    215 in  30.1s =    7.1/s Avg:   419 Min:   337 Max:   656 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =    744 in   106s =    7.0/s Avg:   423 Min:   326 Max:   729 Err:     0 (0.00%)

php7在swoole 下的表现:平均响应时间为230ms 左右,没有超时,很稳定,八核 cpu 消耗 一个cpu 95%,两个20%,其他10%左右。

summary =   1704 in   134s =   12.7/s Avg:   235 Min:   177 Max:  1294 Err:     0 (0.00%)
summary +    410 in    30s =   13.6/s Avg:   219 Min:   192 Max:   490 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =   2114 in   164s =   12.9/s Avg:   232 Min:   177 Max:  1294 Err:     0 (0.00%)
summary +    431 in    30s =   14.4/s Avg:   208 Min:   189 Max:   370 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =   2545 in   194s =   13.1/s Avg:   228 Min:   177 Max:  1294 Err:     0 (0.00%)
summary +    422 in    30s =   14.1/s Avg:   213 Min:   188 Max:   416 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =   2967 in   224s =   13.2/s Avg:   226 Min:   177 Max:  1294 Err:     0 (0.00%)
summary +    426 in    30s =   14.2/s Avg:   210 Min:   190 Max:   327 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =   3393 in   254s =   13.4/s Avg:   224 Min:   177 Max:  1294 Err:     0 (0.00%)

php7在原生的表现:平均响应时间为300左右,没有超时,很稳定,8核cpu 一个在80%,其他四个在15%左右波动,其他为0%。

summary +    213 in    23s =    9.4/s Avg:   311 Min:   247 Max:   685 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary +    306 in    30s =   10.2/s Avg:   294 Min:   240 Max:   448 Err:     0 (0.00%) Active: 3 Started: 3 Finished: 0
summary =    519 in    53s =    9.8/s Avg:   301 Min:   240 Max:   685 Err:     0 (0.00%)

php7 极限

php7 原生 ,excel 500行 ,极限 是 43并发,响应6S左右,cpu普遍达到96%,并出现相当的超时。

summary +    607 in  15.5s =   39.2/s Avg:  4099 Min:   877 Max: 11613 Err:     7 (1.15%) Active: 300 Started: 300 Finished: 0
summary +   1293 in    30s =   43.2/s Avg:  5237 Min:  3302 Max: 35598 Err:    33 (2.55%) Active: 300 Started: 300 Finished: 0
summary =   1900 in  45.4s =   41.8/s Avg:  4874 Min:   877 Max: 35598 Err:    40 (2.11%)
summary +   1353 in  30.2s =   44.8/s Avg:  8237 Min:  3309 Max: 63005 Err:    90 (6.65%) Active: 300 Started: 300 Finished: 0
summary =   3253 in    76s =   43.0/s Avg:  6272 Min:   877 Max: 63005 Err:   130 (4.00%)

php7 原生 swoole excel 500行 ,极限是37/s,响应7.3s 很稳定没有出现超时,cpu 达到上限。

summary +    651 in    19s =   34.9/s Avg:  6306 Min:  2548 Max: 14280 Err:     0 (0.00%) Active: 300 Started: 300 Finished: 0
summary +   1109 in    30s =   37.0/s Avg:  7973 Min:  2449 Max: 23094 Err:     0 (0.00%) Active: 300 Started: 300 Finished: 0
summary =   1760 in    49s =   36.2/s Avg:  7356 Min:  2449 Max: 23094 Err:     0 (0.00%)
summary +   1159 in    30s =   38.6/s Avg:  7784 Min:  2584 Max: 24136 Err:     0 (0.00%) Active: 300 Started: 300 Finished: 0
summary =   2919 in    79s =   37.1/s Avg:  7526 Min:  2449 Max: 24136 Err:     0 (0.00%)

Leave a comment

Your email address will not be published.

*