gitee.com/woood2/luca@v1.0.4/test/ab.md (about) 1 ### 测试环境 2 3 硬件:mac pro 16, 2019 (6核intel i7,16G 内存) 4 web框架:在gin基础上追加了 5 - access日志 6 - prometheus metrics 7 - zipkin(关闭Reporter) 8 9 ### mac os 10 11 -c 50 12 ``` 13 ab -n 10000 -c 50 localhost:8080/hello 14 Requests per second: 18145.43 [#/sec] (mean) 15 Requests per second: 513.93 [#/sec] (mean) 16 ``` 17 18 -c 100 19 ``` 20 ab -n 10000 -c 100 localhost:8080/hello 21 Requests per second: 17293.17 [#/sec] (mean) 22 Requests per second: 773.79 [#/sec] (mean) 23 ``` 24 25 -c 200 26 ``` 27 ab -c 200 -n 10000 localhost:8080/hello 28 Benchmarking localhost (be patient) 29 apr_socket_recv: Connection reset by peer (54) 30 Total of 427 requests completed 31 ``` 32 33 backlog=256 34 ``` 35 sudo sysctl -w kern.ipc.somaxconn=256 36 kern.ipc.somaxconn: 128 -> 256 37 38 重启go进程 39 ``` 40 41 再试 -c 200 42 ``` 43 ab -c 200 -n 10000 localhost:8080/hello 44 Requests per second: 12070.24 [#/sec] (mean) 45 Requests per second: 479.41 [#/sec] (mean) 46 ``` 47 48 backlog=2048 49 ``` 50 sudo sysctl -w kern.ipc.somaxconn=2048 51 kern.ipc.somaxconn: 256 -> 2048 52 53 重启go进程 54 ``` 55 56 -c 2000 57 ``` 58 ab -c 2000 -n 10000 localhost:8080/hello 59 Requests per second: 3608.77 [#/sec] (mean) 60 Requests per second: 419.56 [#/sec] (mean) 61 ``` 62 63 分析 64 ``` 65 第一次ab,速度很快;第二次ab,总是执行到一半卡住 66 检查pprof,未显示异常 67 活动监视器,kernel_task占用最多cpu和磁盘,WindowServer占用内存20G,swap 8G 68 ``` 69 70 重启mac 71 72 ``` 73 WindowServer占用内存400M,swap清零 74 75 ab -c 2000 -n 10000 localhost:8080/hello 76 Requests per second: 5306.58 [#/sec] (mean) 77 Requests per second: 380.10 [#/sec] (mean) 78 79 问题依旧。cpu、内存、磁盘开销很低 80 ``` 81 82 在 VMWare centos 7 中运行gin 83 84 ``` 85 问题依旧。cpu、内存开销很低 86 ``` 87 88 在 VMWare centos 7 中运行ab -c 50 89 ``` 90 ab -c 50 -n 10000 localhost:8080/hello 91 Requests per second: 10722.49 [#/sec] (mean) 92 Requests per second: 10732.86 [#/sec] (mean) 93 Requests per second: 11029.51 [#/sec] (mean) 94 95 问题是 mac中 运行ab导致的 96 ``` 97 98 在 VMWare centos 7(192.168.100.4) 中运行ab -c 2000 99 ``` 100 cat /proc/sys/net/core/somaxconn 101 128 102 103 cat /proc/sys/net/ipv4/tcp_max_syn_backlog 104 128 105 106 ab -c 2000 -n 10000 localhost:8080/hello 107 Complete requests: 10000 108 Failed requests: 0 109 Requests per second: 11560.64 [#/sec] (mean) 110 111 ab -c 10000 -n 10000 localhost:8080/hello 112 Requests per second: 9883.44 [#/sec] (mean) 113 114 ab -c 10000 -n 10000 192.168.100.4:8080/hello 115 Requests per second: 9803.96 [#/sec] (mean) 116 ``` 117 118 分析 119 ``` 120 centos7 上执行ab,似乎不受 backlog限制影响 121 这与hermes项目的测试体验不一致 @todo 验证 122 ```