Fortio(Φορτίο)最初是Istio的负载测试工具,现已发展为独立项目,名称源自希腊语“φορτίο”(意为“负载/负担”)。它是一个快速、轻量级(3Mb Docker镜像,依赖极少)的负载测试工具,同时也是可复用、可嵌入的Go库,支持命令行模式和服务器模式,服务器端包含简单Web UI及结果可视化功能。
Fortio主要用于以指定的每秒查询数(QPS)运行负载测试,记录执行时间直方图并计算百分位数(如p99,表示99%的请求响应时间小于该值)。支持按持续时间、固定调用次数运行,或持续运行直至中断。此外,它还提供类似httpbin的服务器端调试功能,如请求回显、延迟/错误注入、TCP/UDP回显、代理等。
shell# 拉取镜像 docker pull fortio/fortio # 启动服务器模式(含Web UI) docker run -p 8080:8080 -p 8079:8079 fortio/fortio server # 运行负载测试 docker run fortio/fortio load [***]
shell# 需Go 1.16+ go get fortio.org/fortio # 可执行文件位于$GOPATH/bin/fortio
从GitHub Releases下载对应平台的二进制包:
shell# Linux示例 curl -L [***] \ | 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或查看***文档获取全部参数。
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/
shell# 基础测试(默认8 QPS,持续5s) fortio load [***] # 高并发测试(100 QPS,20连接,持续1分钟) fortio load -qps 100 -c 20 -t 1m [***] # POST请求(指定 payload) fortio load -payload "test data" -content-type "application/json" [***]
shell# 启动TCP回显服务器 fortio tcp-echo & # 最大速度测试(10万次调用) fortio load -qps -1 -n *** tcp://localhost:8078
shell# 启动UDP回显服务器 fortio udp-echo & # 最大速度测试(10万次调用) fortio load -qps -1 -n *** udp://localhost:8078/
shell# GRPC ping测试(5次调用) fortio grpcping -n 5 localhost:8079 # TLS加密GRPC测试 fortio grpcping -cacert /path/to/ca.crt localhost:8079
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 [***]
无特殊环境变量,配置主要通过命令行参数实现。
通过-config参数指定配置目录,支持动态更新部分参数(如最大延迟max-echo-delay):
shellfortio server -config /path/to/config-dir
-a自动生成带时间戳的JSON结果(如fortio-20231001-***.json)fortio report命令启动报告服务器,浏览历史结果:
shellfortio report -data-dir /path/to/results
shell$ fortio load -qps -1 -n *** tcp://localhost:8078 Fortio 1.17.0 running at -1 queries per second, 16->16 procs, for *** 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 *** 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 *** 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, *** # target 50% 0.00045737 # target 75% 0.00067221 # target 90% 0.000801115 # target 99% 0.000878457 # target 99.9% 0.000886192 All done *** 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, *** ns) clock skew -*** ... 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 Hub 加速,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
免费版仅支持 docker.io;专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
在 Linux 系统配置镜像加速服务
在 Docker Desktop 配置镜像加速
Docker Compose 项目配置加速
Kubernetes 集群配置 Containerd
在宝塔面板一键配置镜像加速
Synology 群晖 NAS 配置加速
飞牛 fnOS 系统配置镜像加速
极空间 NAS 系统配置加速服务
爱快 iKuai 路由系统配置加速
绿联 NAS 系统配置镜像加速
QNAP 威联通 NAS 配置加速
Podman 容器引擎配置加速
HPC 科学计算容器配置加速
ghcr、Quay、nvcr 等镜像仓库
无需登录使用专属域名加速
需要其他帮助?请查看我们的 常见问题 或 官方QQ群: 13763429