Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mltf

单机高并发 HTTP 压测工具 · 实时 TUI · 自动生成 HTML 报告

License Built with Rust

简体中文 · English


简介

mltf 是一个用 Rust 编写的单机高并发 HTTP 压测工具。压测过程中提供实时终端 UI, 测试结束后自动生成一份自包含的 HTML 报告(图表全部为内联 SVG,无任何外部资源, 单文件即可分享或归档)。

功能特性

  • 基于 Tokio 异步 worker 的高并发压测(默认 50 并发,可调至上千)
  • 实时终端 UI:已用时间、实时吞吐与延迟统计、延迟 sparkline
  • 自动生成 HTML 报告:摘要卡片、延迟直方图、RPS / 平均延迟时间线、百分位表、状态码与错误分布
  • 非交互终端环境(CI、管道重定向)自动降级为 headless 模式
  • TLS 基于 rustls,无需系统 OpenSSL 依赖,交叉编译友好
  • 纯 CLI 参数驱动,零配置文件

构建安装

需要先安装 Rust 工具链,然后:

git clone https://github.com/MCFSO/mltf.git
cd mltf
cargo build --release
# 二进制位于 target/release/mltf(Windows 为 mltf.exe)

快速开始

# 100 并发压测 60 秒,结束后生成 mltf_report.html
mltf -u https://example.com -c 100 --duration 60

# 固定发送 10000 个请求,200 并发,报告写到指定路径
mltf -u https://example.com -c 200 -n 10000 -o report.html

参数说明

参数 默认值 说明
-u, --url <URL> (必填) 目标 URL
-c, --concurrency <N> 50 并发虚拟用户数
-n, --requests <N> (可选) 总请求数;省略时按 --duration 时长运行
--duration <SEC> 30 压测时长(秒),仅在未指定 --requests 时生效
-m, --method <METHOD> GET HTTP 方法
-H, --header <"K: V"> (无) 自定义请求头(可重复)
--api-key <KEY> (无) 以 X-Api-Key 请求头发送 API 密钥
-d, --body <TEXT> (无) 请求体(纯文本),curl 风格别名 -d/--data
--json <JSON> (无) JSON 请求体,自动设置 Content-Type: application/json
--body-file <PATH> (无) 从文件读取请求体(文本/二进制)
--timeout <SEC> 30 单请求超时(秒)
--no-keepalive 关闭 禁用 keep-alive(每个请求新建连接)
--follow 关闭 跟随 3xx 重定向
-o, --output <PATH> mltf_report.html HTML 报告输出路径
--no-tui 关闭 无界面运行(打印进度与摘要,并生成报告)

注意:--body/--data、--json、--body-file 三者互斥,同一时间只能指定一种请求体来源。

使用示例

POST + 自定义请求头 + 请求体:

mltf -u https://api.example.com/echo -m POST -H "Content-Type: application/json" \
     --body '{"hello":"world"}' -c 50 -n 5000

用 --json 快捷方式发送 JSON(自动设置 Content-Type: application/json):

mltf -u https://api.example.com/echo -m POST --json '{"hello":"world"}' -c 50 -n 5000

用 -d/--data 发送表单,或从文件加载请求体:

mltf -u https://api.example.com/echo -m POST -d 'name=mltf&v=1' -c 50 -n 5000
mltf -u https://api.example.com/upload -m POST --body-file payload.bin -c 20 -n 1000

带 API 密钥压测需要鉴权的接口:

mltf -u https://api.example.com/protected --api-key YOUR_KEY -c 50 --duration 30

无界面运行(适合 CI / 脚本;非 TTY 环境下也会自动进入该模式):

mltf -u https://example.com -c 100 -n 1000 --no-tui

TUI 按键

按键 作用
q / Q / Esc / Ctrl+C 停止压测(或退出结束界面)并生成报告

压测自然结束后会进入结束界面,按 q 退出,HTML 报告即写入输出路径。

HTML 报告内容

  • 摘要卡片:总请求数、吞吐、时长、成功率、平均 / p95 / 最大延迟、接收与发送数据量
  • 延迟分布直方图(SVG)
  • RPS 与平均延迟随时间变化曲线(SVG)
  • 百分位表(p50 / p90 / p95 / p99 + min / avg / max)
  • 状态码分布与错误明细

项目结构

src/
  main.rs    — CLI 入口、TUI/headless 分发、报告写入与摘要输出
  args.rs    — clap 参数定义与请求头解析
  engine.rs  — 并发 worker 池、HTTP 执行、结果聚合
  tui.rs     — ratatui + crossterm 实时终端界面
  report.rs  — RunStats 与 HTML+SVG 报告生成
  types.rs   — 百分位统计辅助函数
  util.rs    — 数字/时长/字节等格式化辅助
  report.css — 报告内联样式表

许可证

本项目基于 The Unlicense 发布(进入公有领域)。


English

mltf is a single-machine, high-concurrency HTTP load-testing tool written in Rust. It runs a live TUI while the test is in progress and automatically generates a self-contained HTML report (inline SVG charts, zero external assets) when the test ends.

Features

  • High-concurrency load generation with async Tokio workers (default 50, scale to thousands).
  • Live terminal UI: elapsed time, real-time throughput/latency stats, and a latency sparkline.
  • Auto-generated HTML report: summary cards, latency histogram, RPS / average-latency timeline, percentile table, and status-code/error breakdowns.
  • Automatically falls back to headless mode when stdin is not a TTY (CI, pipes).
  • TLS via rustls — no system OpenSSL dependency.
  • Fully CLI-driven; no config file needed.

Build

Install the Rust toolchain, then:

git clone https://github.com/MCFSO/mltf.git
cd mltf
cargo build --release
# binary: target/release/mltf (mltf.exe on Windows)

Usage

mltf --url <URL> [OPTIONS]
Flag Default Description
-u, --url <URL> (required) Target URL.
-c, --concurrency <N> 50 Number of concurrent virtual users.
-n, --requests <N> (optional) Total number of requests. If omitted, runs for --duration.
--duration <SEC> 30 Duration in seconds (used when --requests is not set).
-m, --method <METHOD> GET HTTP method.
-H, --header <"K: V"> (none) Custom header (repeatable).
--api-key <KEY> (none) API key sent as the X-Api-Key request header.
-d, --body <TEXT> (none) Request body (plain text). Alias: --data.
--json <JSON> (none) Request body as JSON; auto-sets Content-Type: application/json.
--body-file <PATH> (none) Read request body from a file (text/binary).
--timeout <SEC> 30 Per-request timeout.
--no-keepalive off Disable keep-alive (new connection per request).
--follow off Follow HTTP 3xx redirects.
-o, --output <PATH> mltf_report.html HTML report path.
--no-tui off Run headless (print progress/summary, write report).

Note: --body/--data, --json, and --body-file are mutually exclusive — only one request-body source may be supplied.

Examples

Basic 60-second test with 100 concurrent users:

mltf -u https://example.com -c 100 --duration 60

Fixed 10,000 requests with 200 concurrency:

mltf -u https://example.com -c 200 -n 10000 -o report.html

POST JSON with the --json shortcut:

mltf -u https://api.example.com/echo -m POST --json '{"hello":"world"}' -c 50 -n 5000

Send an API key with every request:

mltf -u https://api.example.com/protected --api-key YOUR_KEY -c 50 --duration 30

Headless run (no TUI; also used automatically when stdin is not a TTY):

mltf -u https://example.com -c 100 -n 1000 --no-tui

TUI Controls

q / Q / Esc / Ctrl+C — stop the test (or exit the finished view) and write the report. When the run finishes naturally, the finished view appears; press q to exit.

Report

The generated HTML report includes summary cards (total, throughput, duration, success rate, avg/p95/max latency, data received/sent), a latency histogram, an RPS + average-latency timeline, a percentile table (p50/p90/p95/p99 + min/avg/max), and status-code/error breakdowns — all inline, single-file, ready to share.

License

Released into the public domain under The Unlicense.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages