使用 Docker 快速入门 Bencher 自托管
什么是 Bencher?
Bencher是一套持续型的性能基准测试工具。 你是否曾经因为性能回归影响到了你的用户? Bencher可以防止这种情况的发生。 Bencher让你有能力在性能回归进入生产环境 之前 就进行检测和预防。
- 运行: 使用你喜爱的基准测试工具在本地或CI中执行你的基准测试。
bencher
CLI简单地包装了你现有的基准测验设备并存储其结果。 - 追踪: 追踪你的基准测试结果的趋势。根据源分支、测试床和度量,使用Bencher web控制台来监视、查询和绘制结果图表。
- 捕获: 在CI中捕获性能回归。Bencher使用最先进的、可定制的分析技术在它们进入生产环境之前就检测到性能回归。
基于防止功能回归的原因,在CI中运行单元测试,我们也应该使用Bencher在CI中运行基准测试以防止性能回归。性能问题就是错误!
Bencher 自托管
Bencher 是开源且可自托管的。如果您有兴趣使用 Bencher Cloud,请查看 Bencher Cloud 快速入门教程。本教程将指导您使用 Docker 设置 Bencher 自托管。
🐰 一旦您熟悉使用 Bencher 自托管,可以考虑查看以下资源:
安装 Docker
为了在本教程中运行控制台和 API 服务器,您需要安装 docker
。
检查您是否已安装 docker
。运行以下命令:
docker --version
docker --version
docker --version
docker --version
您应该看到类似以下的输出:
Docker version 20.10.17, build 100c701
如果您的版本号不同也没关系。重要的是这个命令能够正常工作。如果不能,请按照安装 docker
的说明进行操作。
安装 bencher
CLI
选择您的操作系统并运行提供的命令来安装 bencher
CLI。有关更多详细信息,请参阅bencher
CLI安装文档。
⠀
curl --proto '=https' --tlsv1.2 -sSfL https://bencher.dev/download/install-cli.sh | sh
curl --proto '=https' --tlsv1.2 -sSfL https://bencher.dev/download/install-cli.sh | sh
cargo install --git https://github.com/bencherdev/bencher --branch main --locked --force bencher_cli
powershell -c "irm https://bencher.dev/download/install-cli.ps1 | iex"
⠀
现在,让我们检查您是否已安装 bencher
CLI。运行:
bencher --version
bencher --version
bencher --version
bencher --version
您应该会看到:
bencher 0.5.0
运行 bencher up
安装了 docker
和 bencher
CLI 之后,您现在可以使用 bencher up
CLI 子命令 来运行控制台和 API 服务器。 运行:
bencher up
bencher up
bencher up
bencher up
您应该会看到如下内容:
Pulling `ghcr.io/bencherdev/bencher-api:latest` image...Creating `bencher_api` container...Starting `bencher_api` container...
Pulling `ghcr.io/bencherdev/bencher-console:latest` image...Creating `bencher_console` container...Starting `bencher_console` container...
🐰 Bencher Self-Hosted is up and running!Console Server: http://localhost:3000API Server: http://localhost:61016
Press Ctrl+C to stop Bencher Self-Hosted.
🐰 Bencher Self-Hosted logs...
Jan 08 16:49:07.727 INFO 🐰 Bencher API Server v0.5.0...
同样,如果您的输出不同也没关系。 重要的是这个命令能正常工作。
🐰 如果您从
ghcr.io
收到错误提示:"authentication required"
尝试运行:docker logout ghcr.io
选择您的基准测试引擎
如果您已经编写了基准测试,请从下面的列表中选择您的编程语言和基准测试引擎。 否则,请跳过此步骤。 更多详情,请参见基准测试引擎适配器文档。
跟踪你的基准测试
你现在可以开始跟踪你的基准测试结果了!
为此,你将使用 bencher run
命令行子命令 来运行你的基准测试并收集结果。
运行:
⠀
bencher run --host https://localhost:61016 "make benchmarks"
bencher run --host https://localhost:61016 "make benchmarks"
bencher run --host https://localhost:61016 "make benchmarks --benchmark_format=json"
bencher run --host https://localhost:61016 "make benchmarks --benchmark_format=json"
bencher run --host https://localhost:61016 "dotnet run -c Release"
bencher run --host https://localhost:61016 "dotnet run -c Release"
⠀
bencher run --host https://localhost:61016 "go test -bench"
bencher run --host https://localhost:61016 "go test -bench"
bencher run --host https://localhost:61016 --file results.json "java -jar benchmarks.jar -rf json -rff results.json"
bencher run --host https://localhost:61016 --file results.json "java -jar benchmarks.jar -rf json -rff results.json"
bencher run --host https://localhost:61016 "node benchmark.js"
bencher run --host https://localhost:61016 "node benchmark.js"
bencher run --host https://localhost:61016 "node benchmark.js"
bencher run --host https://localhost:61016 "node benchmark.js"
bencher run --host https://localhost:61016 "bencher mock"
bencher run --host https://localhost:61016 "bencher mock"
bencher run --host https://localhost:61016 "asv run"
bencher run --host https://localhost:61016 "asv run"
bencher run --host https://localhost:61016 --file results.json "pytest --benchmark-json results.json benchmarks.py"
bencher run --host https://localhost:61016 --file results.json "pytest --benchmark-json results.json benchmarks.py"
bencher run --host https://localhost:61016 "ruby benchmarks.rb"
bencher run --host https://localhost:61016 "ruby benchmarks.rb"
bencher run --host https://localhost:61016 "cargo +nightly bench"
bencher run --host https://localhost:61016 "cargo +nightly bench"
bencher run --host https://localhost:61016 "cargo bench"
bencher run --host https://localhost:61016 "cargo bench"
bencher run --host https://localhost:61016 "cargo bench"
bencher run --host https://localhost:61016 "cargo bench"
bencher run --host https://localhost:61016 "cargo bench"
bencher run --host https://localhost:61016 "cargo bench"
bencher run --host https://localhost:61016 --file results.json "hyperfine --export-json results.json 'sleep 0.1'"
bencher run --host https://localhost:61016 --file results.json "hyperfine --export-json results.json 'sleep 0.1'"
你可能需要根据你的设置修改基准测试命令。
如果你还没有任何基准测试,你可以只使用 bencher mock
子命令 作为你的基准测试命令来生成一些模拟数据。
如果一切正常,输出的末尾应类似于:
View results:- bencher::mock_0 (Latency): https://localhost:3000/perf/project-abc4567-wxyz123456789?branches=88d5192d-5cd1-47c6-a817-056e5968737c&heads=657a8ee9-1f30-49d4-bd9b-ceed02576d7e&testbeds=f3a5db46-a57e-4caf-b96e-f0c1111eaa67&benchmarks=f7022024-ae16-4782-8f0d-869d65a82930&measures=775999d3-d705-482f-acd8-41947f8e0fbc&start_time=1741390156000&end_time=1743982156000&report=709d3476-51a4-4939-9584-75d9a2c04c54- bencher::mock_1 (Latency): https://localhost:3000/perf/project-abc4567-wxyz123456789?branches=88d5192d-5cd1-47c6-a817-056e5968737c&heads=657a8ee9-1f30-49d4-bd9b-ceed02576d7e&testbeds=f3a5db46-a57e-4caf-b96e-f0c1111eaa67&benchmarks=7a823440-216f-482d-a05f-8bf75e865bba&measures=775999d3-d705-482f-acd8-41947f8e0fbc&start_time=1741390156000&end_time=1743982156000&report=709d3476-51a4-4939-9584-75d9a2c04c54- bencher::mock_2 (Latency): https://localhost:3000/perf/project-abc4567-wxyz123456789?branches=88d5192d-5cd1-47c6-a817-056e5968737c&heads=657a8ee9-1f30-49d4-bd9b-ceed02576d7e&testbeds=f3a5db46-a57e-4caf-b96e-f0c1111eaa67&benchmarks=8d9695ff-f352-4781-9561-3c69012fd9fe&measures=775999d3-d705-482f-acd8-41947f8e0fbc&start_time=1741390156000&end_time=1743982156000&report=709d3476-51a4-4939-9584-75d9a2c04c54- bencher::mock_3 (Latency): https://localhost:3000/perf/project-abc4567-wxyz123456789?branches=88d5192d-5cd1-47c6-a817-056e5968737c&heads=657a8ee9-1f30-49d4-bd9b-ceed02576d7e&testbeds=f3a5db46-a57e-4caf-b96e-f0c1111eaa67&benchmarks=8ef6e256-8084-4afe-a7cf-eaa46384c19d&measures=775999d3-d705-482f-acd8-41947f8e0fbc&start_time=1741390156000&end_time=1743982156000&report=709d3476-51a4-4939-9584-75d9a2c04c54- bencher::mock_4 (Latency): https://localhost:3000/perf/project-abc4567-wxyz123456789?branches=88d5192d-5cd1-47c6-a817-056e5968737c&heads=657a8ee9-1f30-49d4-bd9b-ceed02576d7e&testbeds=f3a5db46-a57e-4caf-b96e-f0c1111eaa67&benchmarks=1205e35a-c73b-4ff9-916c-40838a62ae0b&measures=775999d3-d705-482f-acd8-41947f8e0fbc&start_time=1741390156000&end_time=1743982156000&report=709d3476-51a4-4939-9584-75d9a2c04c54
Claim this project: https://localhost:3000/auth/signup?claim=d4b0cd5a-8422-40af-9872-8e18d5d062c4
你现在可以在浏览器中查看每个基准测试的结果。
点击或复制并粘贴 查看结果
中的链接。
要 认领项目,请点击或复制并粘贴 认领此项目
链接到你的浏览器中。
🐰 恭喜!您已经用 Bencher 自托管跟踪了第一个基准测试结果!🎉