GitLab压测工具GitLab Performance Tool使用方法
大部分公司都采用GitLab作为代码管理系统,而随着公司规模越来越大,对于GitLab服务的压测也需要排上日程,GitLab官方也为我们提供了压测工具GitLab Performance Tool。
官方链接
The GitLab Performance Tool (GPT) tests the server performance of GitLab environments
https://gitlab.com/gitlab-org/quality/performance
使用方法
执行压测之前需要准备下环境,参考文档 https://gitlab.com/gitlab-org/quality/performance/-/blob/main/docs/environment_prep.md
由于使用二进制的方法需要安装一些依赖程序,所以推荐采用Docker的方式来运行。
安装启动Docker
yum install -y docker systemctl start docker
下载压测配置文件
git clone https://gitlab.com/gitlab-org/quality/performance.git
主要的配置文件在k6/config里面,配置文件简单说明如下
environments 环境配置参数(gitlab地址、压测账号、数据源、数据规则)
options 压测参数配置
projects 生成测试数据规则
调整environments里的对应指标的json配置文件里的url参数改为gitlab地址。
生成测试数据
生成测试数据的逻辑图如下:
测试数据是由gpt-data-generator基于指定的配置文件参数来生成的,启动docker之前挂载刚才调整好的k6配置文件目录,启动命令如下:
docker run -it -e ACCESS_TOKEN="xxx" -v /opt/performance/k6:/performance/k6 -v /opt/performance/results:/results --privileged=true gitlab/gpt-data-generator --environment 2k.json
ACCESS_TOKEN为配置账号的Access Token,日志将输出到results目录下,执行后是以交互模式运行的,需要输入Y/N确认,等待数据生成完成即可,预计整个过程大概一个半小时左右,跑数据的过程中若遇到错误信息根据错误描述来解决即可,常见的错误是"Request Entity Too Large Nginx",修改nginx的配置http段里的client_max_body_size参数即可,改大一点。
执行压测
压测的用例主要是由k6完成的,参考文档https://gitlab.com/gitlab-org/quality/performance/-/blob/main/docs/k6.md
通过docker的方式启动压测:
docker run -it -e ACCESS_TOKEN="xxx" -v /opt/performance/k6:/performance/k6 -v /opt/performance/results:/results gitlab/gitlab-performance-tool --environment 2k.json --options 60s_100rps.json
等待压测过程执行完成,预计一个半小时左右完成。
查看压测结果
压测执行完成后,压测结果在results目录下,有csv、json、txt三种格式,结果如下:
* Environment: 10k * Environment Version: 14.3.0-pre `649f624f034` * Option: 60s_200rps * Date: 2021-09-15 * Run Time: 1h 22m 28.81s (Start: 04:33:27 UTC, End: 05:55:56 UTC) * GPT Version: v2.9.0 ❯ Overall Results Score: 97.71% NAME | RPS | RPS RESULT | TTFB AVG | TTFB P90 | REQ STATUS | RESULT ---------------------------------------------------------|-------|----------------------|-----------|-----------------------|----------------|------- api_v4_groups | 200/s | 197.91/s (>160.00/s) | 90.99ms | 106.56ms (<200ms) | 100.00% (>99%) | Passed api_v4_groups_group | 200/s | 95.82/s (>16.00/s) | 1906.35ms | 4461.99ms (<7500ms) | 100.00% (>99%) | Passed api_v4_groups_group_subgroups | 200/s | 197.93/s (>160.00/s) | 108.19ms | 125.85ms (<200ms) | 100.00% (>99%) | Passed api_v4_groups_issues | 200/s | 101.4/s (>48.00/s) | 1800.81ms | 2146.57ms (<3500ms) | 100.00% (>99%) | Passed api_v4_groups_merge_requests | 200/s | 110.44/s (>48.00/s) | 1659.91ms | 1994.68ms (<3500ms) | 100.00% (>99%) | Passed api_v4_groups_projects | 200/s | 164.02/s (>80.00/s) | 1103.89ms | 1487.54ms (<3500ms) | 100.00% (>99%) | Passed api_v4_projects | 200/s | 83.05/s (>24.00/s) | 2212.24ms | 2986.21ms (<7000ms) | 100.00% (>99%) | Passed api_v4_projects_deploy_keys | 200/s | 198.92/s (>160.00/s) | 54.02ms | 58.97ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_issues | 200/s | 196.84/s (>160.00/s) | 203.55ms | 231.11ms (<500ms) | 100.00% (>99%) | Passed api_v4_projects_issues_issue | 200/s | 193.46/s (>160.00/s) | 252.95ms | 289.27ms (<1500ms) | 100.00% (>99%) | Passed api_v4_projects_issues_search | 200/s | 35.71/s (>24.00/s) | 5201.63ms | 10268.43ms (<12000ms) | 100.00% (>99%) | Passed api_v4_projects_languages | 200/s | 198.76/s (>160.00/s) | 50.86ms | 55.27ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_merge_requests | 200/s | 196.21/s (>160.00/s) | 249.51ms | 284.60ms (<400ms) | 100.00% (>99%) | Passed api_v4_projects_merge_requests_merge_request | 200/s | 192.85/s (>80.00/s) | 386.12ms | 466.68ms (<2750ms) | 100.00% (>99%) | Passed api_v4_projects_merge_requests_merge_request_changes | 200/s | 144.57/s (>80.00/s) | 1245.46ms | 1857.22ms (<3500ms) | 100.00% (>99%) | Passed api_v4_projects_merge_requests_merge_request_commits | 200/s | 197.05/s (>160.00/s) | 127.05ms | 144.65ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_merge_requests_merge_request_discussions | 200/s | 195.84/s (>160.00/s) | 191.76ms | 221.69ms (<400ms) | 100.00% (>99%) | Passed api_v4_projects_project | 200/s | 196.27/s (>160.00/s) | 153.78ms | 168.19ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_project_pipelines | 200/s | 198.83/s (>160.00/s) | 70.53ms | 77.84ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_project_pipelines_pipeline | 200/s | 197.59/s (>160.00/s) | 84.75ms | 94.62ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_project_services | 200/s | 199.07/s (>160.00/s) | 53.07ms | 58.65ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_releases | 200/s | 195.91/s (>160.00/s) | 99.19ms | 105.87ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_branches | 200/s | 195.49/s (>160.00/s) | 55.98ms | 56.44ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_branches_branch | 200/s | 198.41/s (>160.00/s) | 86.91ms | 94.46ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_branches_search | 200/s | 198.33/s (>48.00/s) | 51.15ms | 54.80ms (<6000ms) | 100.00% (>99%) | Passed api_v4_projects_repository_commits | 200/s | 198.65/s (>160.00/s) | 79.91ms | 87.63ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_commits_commit | 200/s | 198.74/s (>160.00/s) | 73.70ms | 79.73ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_commits_commit_diff | 200/s | 197.76/s (>160.00/s) | 123.19ms | 133.64ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_compare | 200/s | 194.73/s (>160.00/s) | 60.41ms | 63.50ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_files_file | 200/s | 198.72/s (>160.00/s) | 72.66ms | 79.92ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_files_file_blame | 200/s | 39.55/s (>1.60/s) | 4633.10ms | 6289.95ms (<35000ms) | 100.00% (>15%) | Passed api_v4_projects_repository_files_file_raw | 200/s | 198.63/s (>160.00/s) | 76.25ms | 82.58ms (<200ms) | 100.00% (>99%) | Passed api_v4_projects_repository_tags | 200/s | 87.65/s (>32.00/s) | 2100.06ms | 3651.99ms (<10000ms) | 100.00% (>99%) | Passed api_v4_projects_repository_tree | 200/s | 198.13/s (>160.00/s) | 100.93ms | 110.12ms (<200ms) | 100.00% (>99%) | Passed api_v4_search_global | 200/s | 177.22/s (>64.00/s) | 2866.21ms | 4368.75ms (<13000ms) | 100.00% (>80%) | Passed api_v4_search_groups | 200/s | 189.69/s (>64.00/s) | 343.43ms | 417.73ms (<16000ms) | 100.00% (>80%) | Passed api_v4_search_projects | 200/s | 173.4/s (>64.00/s) | 2101.39ms | 3920.91ms (<16000ms) | 100.00% (>80%) | Passed api_v4_user | 200/s | 198.68/s (>160.00/s) | 47.54ms | 51.36ms (<200ms) | 100.00% (>99%) | Passed api_v4_users | 200/s | 198.25/s (>160.00/s) | 93.55ms | 103.15ms (<200ms) | 100.00% (>99%) | Passed git_clone | 8/s | 1.06/s (>0.26/s) | 339.79ms | 592.56ms (<800ms) | 100.00% (>99%) | Passed git_ls_remote | 20/s | 19.91/s (>16.00/s) | 64.74ms | 77.27ms (<200ms) | 100.00% (>99%) | Passed git_pull | 20/s | 19.74/s (>16.00/s) | 103.70ms | 150.25ms (<400ms) | 100.00% (>99%) | Passed git_push | 4/s | 3.29/s (>3.20/s) | 899.42ms | 584.33ms (<1000ms) | 100.00% (>99%) | Passed scenario_api_list_group_variables | 2/s | 1.98/s (>1.60/s) | 102.84ms | 113.66ms (<200ms) | 100.00% (>99%) | Passed scenario_api_list_project_variables | 2/s | 1.95/s (>1.60/s) | 128.27ms | 131.37ms (<200ms) | 100.00% (>99%) | Passed scenario_api_new_branches | 2/s | 1.97/s (>1.60/s) | 383.29ms | 464.34ms (<1500ms) | 100.00% (>99%) | Passed scenario_api_new_commits | 2/s | 1.98/s (>1.60/s) | 412.21ms | 470.60ms (<700ms) | 100.00% (>99%) | Passed scenario_api_new_group_variables | 2/s | 2.01/s (>1.60/s) | 90.84ms | 116.13ms (<200ms) | 100.00% (>99%) | Passed scenario_api_new_issues | 2/s | 1.95/s (>1.60/s) | 301.20ms | 475.66ms (<2500ms) | 100.00% (>99%) | Passed scenario_api_new_project_variables | 2/s | 1.98/s (>1.60/s) | 123.25ms | 133.12ms (<200ms) | 100.00% (>99%) | Passed web_group | 20/s | 19.88/s (>16.00/s) | 209.43ms | 231.35ms (<400ms) | 100.00% (>99%) | Passed web_group_issues | 20/s | 19.19/s (>16.00/s) | 346.62ms | 411.46ms (<500ms) | 100.00% (>99%) | Passed web_group_merge_requests | 20/s | 19.29/s (>16.00/s) | 309.72ms | 344.40ms (<500ms) | 100.00% (>99%) | Passed web_project | 20/s | 19.32/s (>16.00/s) | 338.64ms | 369.59ms (<500ms) | 100.00% (>99%) | Passed web_project_branches | 20/s | 19.14/s (>16.00/s) | 400.80ms | 444.84ms (<800ms) | 100.00% (>99%) | Passed web_project_branches_search | 20/s | 18.57/s (>16.00/s) | 820.57ms | 863.08ms (<1300ms) | 100.00% (>99%) | Passed web_project_commit | 20/s | 17.81/s (>6.40/s) | 810.20ms | 2223.75ms (<2900ms) | 100.00% (>99%) | Passed web_project_commits | 20/s | 18.99/s (>16.00/s) | 487.74ms | 531.48ms (<750ms) | 100.00% (>99%) | Passed web_project_file_blame | 20/s | 6.28/s (>0.16/s) | 2752.56ms | 3358.42ms (<7000ms) | 100.00% (>99%) | Passed web_project_file_rendered | 20/s | 19.26/s (>12.80/s) | 602.28ms | 1065.49ms (<1700ms) | 100.00% (>99%) | Passed web_project_file_source | 20/s | 19.12/s (>1.60/s) | 647.18ms | 941.20ms (<1700ms) | 100.00% (>99%) | Passed web_project_files | 20/s | 19.46/s (>16.00/s) | 184.00ms | 265.60ms (<800ms) | 100.00% (>99%) | Passed web_project_issue | 20/s | 19.5/s (>16.00/s) | 366.83ms | 950.48ms (<2000ms) | 100.00% (>99%) | Passed web_project_issues | 20/s | 19.1/s (>16.00/s) | 359.84ms | 387.49ms (<500ms) | 100.00% (>99%) | Passed web_project_issues_search | 20/s | 19.44/s (>16.00/s) | 335.12ms | 363.04ms (<500ms) | 100.00% (>99%) | Passed web_project_merge_request | 20/s | 19.73/s (>6.40/s) | 311.30ms | 531.47ms (<7500ms) | 100.00% (>99%) | Passed web_project_merge_request_changes | 20/s | 19.59/s (>16.00/s) | 263.15ms | 342.48ms (<1500ms) | 100.00% (>99%) | Passed web_project_merge_request_commits | 20/s | 18.52/s (>9.60/s) | 714.30ms | 794.06ms (<1750ms) | 100.00% (>99%) | Passed web_project_merge_requests | 20/s | 19.16/s (>16.00/s) | 373.34ms | 425.83ms (<500ms) | 100.00% (>99%) | Passed web_project_pipelines | 20/s | 19.39/s (>9.60/s) | 356.68ms | 522.10ms (<1000ms) | 100.00% (>99%) | Passed web_project_pipelines_pipeline | 20/s | 19.4/s (>16.00/s) | 591.34ms | 1299.15ms (<2500ms) | 100.00% (>99%) | Passed web_project_repository_compare | 20/s | 3.51/s (>0.80/s) | 5083.90ms | 5587.22ms (<7500ms) | 100.00% (>99%) | Passed web_project_tags | 20/s | 18.34/s (>12.80/s) | 810.77ms | 901.26ms (<1500ms) | 100.00% (>99%) | Passed web_search_global | 20/s | 19.55/s (>16.00/s) | 85.60ms | 169.96ms (<2000ms) | 100.00% (>99%) | Passed web_search_groups | 20/s | 19.2/s (>16.00/s) | 77.42ms | 97.76ms (<3000ms) | 100.00% (>99%) | Passed web_search_projects | 20/s | 19.61/s (>16.00/s) | 82.20ms | 131.70ms (<3000ms) | 100.00% (>99%) | Passed web_user | 20/s | 19.92/s (>9.60/s) | 99.80ms | 119.94ms (<4000ms) | 100.00% (>99%) | Passed
压测报告各字段说明如下:
上面的部分是环境、测试和 GPT 版本的统计信息。
接下来是环境的总体结果得分。该值是根据所有测试结果计算得出的,并以蒸馏值的形式呈现,以显示环境的整体表现。通常,性能良好的环境应高于 90%。
下面的表格是每次测试运行的主要结果。在此表中,每列显示以下内容:
NAME- 测试运行的名称。匹配文件tests夹中的测试文件名
RPS - 测试期间使用的 RPS 目标。
RPS RESULT - 达到的 RPS 及其通过阈值。
TTFB AVG-以毫秒为单位的平均第一个字节时间(TTFB)。
TTFB P90- TTFB的第 90 个百分位数及其通过阈值。
TTFB P95可以通过将GPT_TTFB_P95环境变量传递给 GPT来选择性地输出列。
REQ STATUS - 测试发出的返回成功状态(返回 HTTP 代码 200 / 201)的请求的百分比及其通过阈值。
RESULT - 基于阈值的测试的最终结果。