Fortio(Φορτίο)最初是Istio的负载测试工具,现已发展为独立项目,名称源自希腊语“φορτίο”(意为“负载/负担”)。它是一个快速、轻量级(3Mb Docker镜像,依赖极少)的负载测试工具,同时也是可复用、可嵌入的Go库,支持命令行模式和服务器模式,服务器端包含简单Web UI及结果可视化功能。
Fortio主要用于以指定的每秒查询数(QPS)运行负载测试,记录执行时间直方图并计算百分位数(如p99,表示99%的请求响应时间小于该值)。支持按持续时间、固定调用次数运行,或持续运行直至中断。此外,它还提供类似httpbin的服务器端调试功能,如请求回显、延迟/错误注入、TCP/UDP回显、代理等。
Docker(推荐)
shell# 拉取镜像 docker pull fortio/fortio # 启动服务器模式(含Web UI) docker run -p 8080:8080 -p 8079:8079 fortio/fortio server # 运行负载测试 docker run fortio/fortio load http://www.google.com
源码安装
shell# 需Go 1.16+ go get fortio.org/fortio # 可执行文件位于$GOPATH/bin/fortio
二进制包
从https://github.com/fortio/fortio/releases%E4%B8%8B%E8%BD%BD%E5%AF%B9%E5%BA%94%E5%B9%B3%E5%8F%B0%E7%9A%84%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%8C%85%EF%BC%9A
shell# Linux示例 curl -L https://github.com/fortio/fortio/releases/download/v1.17.0/fortio-linux_x64-1.17.0.tgz \ | sudo tar -C / -xvzpf -
包管理器
brew install fortiofortio.exe核心参数(负载测试)
| 参数 | 描述示例 |
|---|---|
-qps rate | 查询每秒数(QPS),0表示无等待/最大速度(默认8) |
-c connections | 并行连接数(协程数)(默认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),建议配合.json后缀以便report命令识别 |
-labels "l1 l2" | 添加自定义标签到结果JSON(默认包含目标URL和主机名) |
完整参数列表
执行fortio help或查看https://github.com/fortio/fortio/wiki%E8%8E%B7%E5%8F%96%E5%85%A8%E9%83%A8%E5%8F%82%E6%95%B0%E3%80%82
1. 启动服务器(含Web UI)
shell# 默认端口(8080: HTTP服务,8079: GRPC服务) fortio server # 自定义HTTP端口 fortio server -http-port 10.10.10.10:8088 # Unix域套接字 fortio server --http-port /tmp/fortio-uds-http
Web UI访问地址:http://localhost:8080/fortio/
2. HTTP负载测试
shell# 基础测试(默认8 QPS,持续5s) fortio load http://www.google.com # 高并发测试(100 QPS,20连接,持续1分钟) fortio load -qps 100 -c 20 -t 1m https://api.example.com/v1/health # POST请求(指定 payload) fortio load -payload "test data" -content-type "application/json" https://api.example.com/v1/submit
3. TCP负载测试
shell# 启动TCP回显服务器 fortio tcp-echo & # 最大速度测试(10万次调用) fortio load -qps -1 -n 100000 tcp://localhost:8078
4. UDP负载测试
shell# 启动UDP回显服务器 fortio udp-echo & # 最大速度测试(10万次调用) fortio load -qps -1 -n 100000 udp://localhost:8078/
5. GRPC测试
shell# GRPC ping测试(5次调用) fortio grpcping -n 5 localhost:8079 # TLS加密GRPC测试 fortio grpcping -cacert /path/to/ca.crt localhost:8079
服务器模式(含Web UI)
shelldocker run -d \ -p 8080:8080 \ -p 8079:8079 \ --name fortio-server \ fortio/fortio server
访问http://localhost:8080/fortio/查看Web UI。
负载测试模式
shell# 测试本地服务(需确保容器网络可达) docker run --rm fortio/fortio load -qps 100 -t 30s http://host.docker.internal:8080/debug
无特殊环境变量,配置主要通过命令行参数实现。
通过-config参数指定配置目录,支持动态更新部分参数(如最大延迟max-echo-delay):
shellfortio server -config /path/to/config-dir
-a自动生成带时间戳的JSON结果(如fortio-20231001-123456.json)fortio report命令启动报告服务器,浏览历史结果:
shellfortio report -data-dir /path/to/results
shell$ fortio load -qps -1 -n 100000 tcp://localhost:8078 Fortio 1.17.0 running at -1 queries per second, 16->16 procs, for 100000 calls: tcp://localhost:8078 20:01:31 I tcprunner.go:218> Starting tcp test for tcp://localhost:8078 with 4 threads at -1.0 qps Starting at max qps with 4 thread(s) [gomax 16] for exactly 100000 calls (25000 per thread + 0) 20:01:32 I periodic.go:558> T003 ended after 1.240585427s : 25000 calls. qps=20151.77629520873 ... Aggregated Function Time : count 100000 avg 4.9404876e-05 +/- 1.145e-05 min 2.7697e-05 max 0.000887051 sum 4.94048763 # range, mid point, percentile, count >= 2.7697e-05 <= 0.000887051 , 0.000457374 , 100.00, 100000 # target 50% 0.00045737 # target 75% 0.00067221 # target 90% 0.000801115 # target 99% 0.000878457 # target 99.9% 0.000886192 All done 100000 calls (plus 0 warmup) 0.049 ms avg, 80495.0 qps
关键指标:
shell$ fortio grpcping -n 5 localhost 22:36:55 I pingsrv.go:150> Ping RTT 212000 (avg of 259000, 217000, 160000 ns) clock skew -10500 ... RTT histogram usec : count 15 avg 144.73333 +/- 44.48 min 101 max 259 sum 2171 # range, mid point, percentile, count >= 101 <= 110 , 105.5 , 26.67, 4 > 110 <= 120 , 115 , 40.00, 2 ... # target 50% 130
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务