istio/fortio.echosrvFortio(Φορτίο)最初是 Istio 的负载测试工具,现已发展为独立项目,也被 Meshery 等项目采用。它能以指定的每秒查询数(QPS)运行,记录执行时间直方图并计算百分位数(如 p99),可运行指定时长、固定调用次数或直至中断。名称源自希腊语“φορτίο”,意为“负载/负担”。
shelldocker run -p 8080:8080 -p 8079:8079 fortio/fortio server &
此命令启动 Fortio 服务器,映射 HTTP 端口 8080 和 gRPC 端口 8079,可通过 http://localhost:8080/fortio/ 访问 Web UI。
shelldocker run fortio/fortio load [***]
对指定目标(如 [***])执行负载测试。
Go 安装:
shellgo get fortio.org/fortio
二进制下载:从 GitHub Releases 下载对应平台的二进制文件。
macOS(Homebrew):
shellbrew install fortio
Windows:下载 ZIP 包并解压,在命令提示符中运行 fortio.exe server。
| 参数 | 描述与示例 |
|---|---|
-qps rate | 每秒查询数(QPS),0 表示无等待/最大 QPS(默认 8) |
-c connections | 并行连接数(goroutine/线程数,默认 4) |
-t duration | 测试持续时间(如 -t 30m 表示 30 分钟,默认 5s),0 表示运行至中断 |
-n numcalls | 固定调用次数,替代持续时间模式(默认 0,使用 -t) |
-r resolution | 直方图最低桶分辨率(秒,默认 0.001,即 1ms),建议设为预期典型延迟的 1/10 |
-H "header: value" | 添加请求头,可多次指定(如 -H "Host: example.com") |
-a | 自动保存 JSON 结果,文件名基于标签和时间戳 |
-json filename | JSON 结果输出文件(或 - 表示 stdout),默认相对 -data-dir 目录 |
-labels "l1 l2 ..." | 添加到 JSON 结果的额外标签,默认包含目标 URL 和主机名 |
运行 fortio help 查看所有命令和参数,包括 gRPC、TCP、UDP 测试相关参数。
shellfortio server & # 输出示例: # 14:11:05 I fortio_main.go:171> 未使用动态标志监控(使用 -config 设置监控目录) # Fortio 1.17.0 tcp-echo server listening on [::]:8078 # Fortio 1.17.0 grpc 'ping' server listening on [::]:8079 # Fortio 1.17.0 https redirector server listening on [::]:8081 # Fortio 1.17.0 echo server listening on [::]:8080 # Data directory is /Users/ldemailly/go/src/fortio.org/fortio # UI started - visit: http://localhost:8080/fortio/
shellfortio server -http-port 10.10.10.10:8088
将 HTTP 服务器绑定到 10.10.10.10:8088。
shell# 启动 HTTP 服务器监听 Unix 域套接字 fortio server --http-port /tmp/fortio-uds-http & # 通过 Unix 域套接字访问 fortio curl -unix-socket=/tmp/fortio-uds-http [***]
shell# 启动 TCP 回显服务器 fortio tcp-echo & # 对 TCP 服务器执行最大 QPS 负载测试(*** 次调用) fortio load -qps -1 -n *** tcp://localhost:8078
shell# 启动 UDP 回显服务器 fortio udp-echo & # 对 UDP 服务器执行最大 QPS 负载测试(*** 次调用) fortio load -qps -1 -n *** udp://localhost:8078/
shellfortio grpcping -n 5 localhost
向本地 gRPC 服务器发送 5 次 Ping 请求。
shell# 启动带 TLS 的 Fortio 服务器 fortio server -cert /path/to/server.crt -key /path/to/server.key # 使用 CA 证书连接 fortio grpcping -cacert /path/to/ca.crt localhost
shellfortio load [***]
以默认 QPS(8)和持续时间(5s)测试 [***]。
负载测试结果包含以下关键指标:
例如,测试输出中可能包含:
Ended after 5.059691387s : 40 calls. qps=7.9056 Aggregated Function Time : count 40 avg 0.060587641 +/- 0.006564 min 0.052549016 max 0.089893269 sum 2.42350566 # target 50% 0.0605556 # target 75% 0.065 # target 90% 0.075 # target 99% 0.0849466
表示 40 次调用,QPS 约 7.9,平均延迟 0.06s,p99 延迟 0.0849s。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务