性能压力测试
发布于: 2020 年 07 月 22 日
性能压测的一般规律
性能压测的时候,随着并发压力的增加,系统响应时间和吞吐量如何变化?
性能压测中,随着并发量的提高,TPS 的变化可以分为三个阶段:性能测试阶段、负载测试阶段、压力测试阶段。
首先是性能测试阶段,随着并发数的上升,TPS 也线性提高,原因是系统开始压测时,CPU、内存、IO 资源充裕。因此业务需求得到了及时的响应。
在负载测试阶段,随着系统负载的升高,各种资源的瓶颈也开始显现,因此只能维持在较为均衡的状态。
在压力测试阶段,系统发负载达到某个资源的极限,因此系统性能开始下降,直至服务宕掉。
真实的情况
任何理想的模型都是为了说明问题。那么基于用户的真实的压测是什么情况呢?
使用一个 go 语言编写的工具来真实压测一下。压测工具
压测的目标是极客时间 28 | 高性能架构:除了代码,你还可以在哪些地方优化性能?
压测命令如下,分别使用并发为 10、20、50、100、1000、2000 压测。
./go-stress-testing-mac -c 2000 -n 20 -u https://time.geekbang.org/search\?q\=%E5%90%8E%E7%AB%AF
./go-stress-testing-mac -c 10 -n 50 -u https://time.geekbang.org/search\?q\=%E5%90%8E%E7%AB%AF 开始启动 并发数:10 请求数:50 请求参数:request: form:http url:https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF method:GET headers:map[] data: verify:statusCode timeout:30s debug:false─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬──────── 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼──────── 1s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 2s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 3s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 4s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 5s│ 6│ 6│ 0│ 2.01│ 4979.69│ 4971.37│ 497.46│200:6 6s│ 7│ 7│ 0│ 1.98│ 5424.39│ 4971.37│ 503.88│200:7 7s│ 10│ 10│ 0│ 1.78│ 6954.82│ 4971.37│ 561.34│200:10 8s│ 10│ 10│ 0│ 1.78│ 6954.82│ 4971.37│ 561.34│200:10 9s│ 10│ 33│ 0│ 3.74│ 6954.82│ 282.20│ 267.61│200:33 10s│ 10│ 56│ 0│ 5.72│ 6954.82│ 254.51│ 174.71│200:56 11s│ 10│ 80│ 0│ 7.42│ 6954.82│ 254.51│ 134.81│200:80 12s│ 10│ 106│ 0│ 8.90│ 6954.82│ 246.30│ 112.31│200:106 13s│ 10│ 126│ 0│ 9.86│ 6954.82│ 246.30│ 101.39│200:126 14s│ 10│ 153│ 0│ 11.05│ 6954.82│ 246.30│ 90.48│200:153 15s│ 10│ 179│ 0│ 12.15│ 6954.82│ 246.30│ 82.34│200:179 16s│ 10│ 209│ 0│ 13.19│ 6954.82│ 246.30│ 75.81│200:209 17s│ 10│ 235│ 0│ 14.00│ 6954.82│ 246.30│ 71.43│200:235 18s│ 10│ 265│ 0│ 14.80│ 6954.82│ 246.30│ 67.55│200:265 19s│ 10│ 292│ 0│ 15.50│ 6954.82│ 246.30│ 64.51│200:292 20s│ 10│ 319│ 0│ 16.14│ 6954.82│ 246.30│ 61.97│200:319 21s│ 10│ 348│ 0│ 16.78│ 6954.82│ 246.30│ 59.59│200:348 22s│ 10│ 376│ 0│ 17.28│ 6954.82│ 246.30│ 57.86│200:376 23s│ 10│ 407│ 0│ 17.85│ 6954.82│ 246.30│ 56.03│200:407 24s│ 10│ 437│ 0│ 18.36│ 6954.82│ 246.30│ 54.47│200:437 25s│ 10│ 457│ 0│ 18.51│ 6954.82│ 246.30│ 54.04│200:457 26s│ 10│ 487│ 0│ 18.92│ 6954.82│ 246.30│ 52.86│200:487
压测到 1000 开始触发网站的保护机制。
./go-stress-testing-mac -c 1000 -n 20 -u https://time.geekbang.org/search\?q\=%E5%90%8E%E7%AB%AF 开始启动 并发数:1000 请求数:20 请求参数:request: form:http url:https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF method:GET headers:map[] data: verify:statusCode timeout:30s debug:false─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬──────── 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼──────── 1s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 2s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 3s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 4s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 5s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 6s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 7s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 8s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 9s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 10s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 11s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 12s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 13s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 14s│ 208│ 208│ 0│ 73.04│14002.06│13295.66│ 13.69│200:208 15s│ 405│ 405│ 0│ 72.84│14456.61│13295.66│ 13.73│200:405 16s│ 412│ 756│ 0│ 120.96│15497.36│ 1423.54│ 8.27│200:756 17s│ 419│ 877│ 0│ 134.02│16569.00│ 1199.98│ 7.46│200:877 18s│ 427│ 1205│ 0│ 167.22│17718.99│ 1196.90│ 5.98│200:1205 19s│ 475│ 1302│ 0│ 158.39│19009.32│ 1196.90│ 6.31│200:1302 20s│ 508│ 1614│ 0│ 169.28│19949.12│ 1196.90│ 5.91│200:1614 21s│ 572│ 1880│ 0│ 167.07│20859.10│ 1196.90│ 5.99│200:1880 22s│ 690│ 2178│ 0│ 154.47│21827.77│ 1196.90│ 6.47│200:2178 23s│ 738│ 2486│ 0│ 157.80│22634.48│ 1196.90│ 6.34│200:2486 24s│ 766│ 2645│ 0│ 157.89│23322.31│ 1196.90│ 6.33│200:2645 25s│ 793│ 3018│ 0│ 164.63│24591.10│ 1196.90│ 6.07│200:3018 26s│ 809│ 3365│ 0│ 171.43│25340.24│ 1196.90│ 5.83│200:3365 27s│ 809│ 3365│ 0│ 171.43│25340.24│ 1196.90│ 5.83│200:3365 28s│ 809│ 3365│ 0│ 171.43│25340.24│ 1196.90│ 5.83│200:3365 29s│ 809│ 3365│ 0│ 171.43│25340.24│ 1196.90│ 5.83│200:3365请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers) 30s│ 811│ 3365│ 2│ 170.90│30003.03│ 1196.90│ 5.85│200:3365;509:2请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
压 2000 也能跑,会不时触发保护机制。
./go-stress-testing-mac -c 2000 -n 20 -u https://time.geekbang.org/search\?q\=%E5%90%8E%E7%AB%AF 开始启动 并发数:2000 请求数:20 请求参数:request: form:http url:https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF method:GET headers:map[] data: verify:statusCode timeout:30s debug:false─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬──────── 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│ 错误码─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼──────── 1s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 2s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 3s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 4s│ 0│ 0│ 0│ 0.00│ 0.00│ 0.00│ 0.00│ 5s│ 177│ 177│ 0│ 446.38│ 4850.26│ 4278.32│ 2.24│200:177 6s│ 809│ 809│ 0│ 407.27│ 5648.95│ 4278.32│ 2.46│200:809 7s│ 1066│ 1066│ 0│ 389.51│ 6633.78│ 4278.32│ 2.57│200:1066 8s│ 1337│ 1368│ 0│ 364.86│ 7540.24│ 2181.75│ 2.74│200:1368 9s│ 1632│ 1765│ 0│ 347.50│ 8513.70│ 2181.75│ 2.88│200:1765 10s│ 1687│ 1895│ 0│ 347.67│ 9728.63│ 2181.75│ 2.88│200:1895 11s│ 1731│ 2009│ 0│ 344.81│10632.92│ 2181.75│ 2.90│200:2009 12s│ 1754│ 2298│ 0│ 345.85│11714.21│ 2181.75│ 2.89│200:2298 13s│ 1770│ 2506│ 0│ 339.94│12832.72│ 2181.75│ 2.94│200:2506 14s│ 1798│ 2653│ 0│ 334.34│13748.38│ 2181.75│ 2.99│200:2653 15s│ 1882│ 3051│ 0│ 320.79│14266.46│ 2181.75│ 3.12│200:3051 16s│ 1889│ 3258│ 0│ 317.07│15564.73│ 2181.75│ 3.15│200:3258 17s│ 1983│ 3852│ 0│ 287.77│16535.87│ 2181.75│ 3.47│200:3852 18s│ 1984│ 3883│ 0│ 287.26│16981.61│ 2181.75│ 3.48│200:3883 19s│ 1984│ 3897│ 0│ 286.31│16981.61│ 2181.75│ 3.49│200:3897 20s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 21s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 22s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 23s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 24s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 25s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 26s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 27s│ 1986│ 3917│ 0│ 285.69│18829.71│ 2181.75│ 3.50│200:3917 28s│ 1986│ 3939│ 0│ 283.80│22918.05│ 2181.75│ 3.52│200:3939 29s│ 1986│ 3983│ 0│ 280.81│22918.05│ 2181.75│ 3.56│200:3983 30s│ 1986│ 4114│ 0│ 271.08│22918.05│ 2181.75│ 3.69│200:4114请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers) 31s│ 2000│ 4271│ 14│ 254.33│30005.57│ 2181.75│ 3.93│200:4271;509:14 32s│ 2000│ 4422│ 14│ 244.83│30005.57│ 2181.75│ 4.08│200:4422;509:14 33s│ 2000│ 4468│ 14│ 241.96│30005.57│ 2181.75│ 4.13│200:4468;509:14 34s│ 2000│ 4468│ 14│ 241.96│30005.57│ 2181.75│ 4.13│200:4468;509:14请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers) 35s│ 2000│ 4499│ 15│ 239.62│30005.57│ 2181.75│ 4.17│200:4499;509:15请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)请求失败: Get "https://time.geekbang.org/search?q=%E5%90%8E%E7%AB%AF": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
真实图形是这样的:
看,现实就是比理想曲折。这是从用户角度看到的真实的压测。
划线
评论
复制
发布于: 2020 年 07 月 22 日阅读数: 99
dongge
关注
还未添加个人签名 2017.10.19 加入
还未添加个人简介
评论 (1 条评论)