Skip to content

withRiver/disk-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

磁盘性能评估工具 (Disk Benchmark)

一个用于评估磁盘 I/O 性能的工具,支持 Web 界面和终端交互模式,提供带宽测试、IOPS 测试、延迟测试、块大小探测和内存对比等多种测试类型。

功能特性

  • 带宽测试 - 测量顺序读写带宽 (MB/s)
  • 块大小探测 - 找出最优 I/O 块大小 (4KB ~ 16MB)
  • IOPS 测试 - 测量随机读写 IOPS
  • 延迟测试 - 测量 I/O 延迟分布 (P50/P90/P99)
  • 内存对比 - 对比磁盘与内存性能差异
  • 完整测试 - 运行所有测试项目
  • 双模式 - 支持 Web 界面和终端交互模式

技术栈

  • 后端: Go 1.21+ / Gin 框架 / Cobra CLI
  • 前端: React 18 / TypeScript 5.x / Vite / TailwindCSS
  • 通信: REST API + WebSocket 实时进度

快速开始

环境要求

  • Go 1.21+
  • Node.js 18+ (仅 Web 模式需要)
  • npm 8+ (仅 Web 模式需要)

终端交互模式 (推荐)

# 编译 CLI 工具
cd backend
./build-cli.sh

# 启动交互模式
./disk-benchmark

交互模式支持:

  • 使用 ↑/↓ 方向键选择测试类型
  • 使用 ←/→ 方向键选择测试路径 (/tmp 或 /data/workspace)
  • 可调整文件大小 (64MB ~ 4GB)
  • 实时显示测试进度
  • 支持 Ctrl+C / ESC / q 取消测试

命令行模式

# 运行带宽测试
./disk-benchmark run -p /tmp -t bandwidth --file-size 1GB

# 运行完整测试
./disk-benchmark run -p /tmp -t full --file-size 2GB

# 查看可用测试类型
./disk-benchmark list

# 查看配置
./disk-benchmark config show

# 清理测试文件
./disk-benchmark clean -p /tmp

# 输出为 JSON 格式
./disk-benchmark run -p /tmp -t bandwidth -f json

# 输出为 CSV 格式
./disk-benchmark run -p /tmp -t bandwidth -f csv -o result.csv

Web 模式部署

# 默认部署到 8088 端口
./deploy.sh deploy

# 指定端口部署
./deploy.sh -p 9000 deploy

# 通过环境变量指定端口
PORT=9000 ./deploy.sh deploy

部署成功后,访问 http://localhost:8088 (或自定义端口)

部署脚本使用 (Web 模式)

用法: ./deploy.sh [选项] [命令]

命令:
  deploy    完整部署(编译+构建+启动)[默认]
  build     仅编译构建
  start     仅启动服务
  stop      停止服务
  restart   重启服务
  status    查看服务状态
  logs      查看日志
  help      显示帮助

选项:
  -p, --port <端口>    指定服务端口 (默认: 8088)
  -l, --log <文件>     指定日志文件 (默认: /tmp/disk-benchmark.log)
  -h, --help           显示帮助

示例:
  ./deploy.sh deploy -p 9000           # 部署到9000端口
  ./deploy.sh -p 8080 start            # 在8080端口启动服务
  ./deploy.sh stop                     # 停止服务
  ./deploy.sh status                   # 查看服务状态

手动构建

CLI 工具

cd backend
./build-cli.sh
# 或手动编译
go build -o disk-benchmark ./cmd/cli/

Web 后端

cd backend
go build -o disk-benchmark ./cmd/server/main.go
./disk-benchmark -port 8088 -static ../frontend/dist -reports ../reports

前端

cd frontend
npm install
npm run build

项目结构

disk-benchmark/
├── backend/                 # Go 后端
│   ├── cmd/
│   │   ├── server/          # Web 服务入口
│   │   └── cli/             # CLI 工具入口
│   ├── internal/
│   │   ├── api/             # HTTP API
│   │   ├── benchmark/       # 测试逻辑
│   │   ├── cli/             # CLI 交互模式
│   │   ├── models/          # 数据模型
│   │   ├── report/          # 报告生成
│   │   └── websocket/       # WebSocket
│   └── pkg/directio/        # Direct I/O 支持
├── frontend/                # React 前端
│   ├── src/
│   │   ├── components/      # 组件
│   │   ├── pages/           # 页面
│   │   ├── services/        # API 服务
│   │   └── types/           # 类型定义
│   └── dist/                # 构建输出
├── reports/                 # 测试报告
├── deploy.sh                # Web 部署脚本
└── README.md

API 接口

方法 路径 说明
GET /api/v1/system/info 获取系统信息
GET /api/v1/disks 获取可用目录列表
POST /api/v1/tasks 创建测试任务
GET /api/v1/tasks 获取任务列表
GET /api/v1/tasks/:id 获取任务详情
POST /api/v1/tasks/:id/start 启动任务
POST /api/v1/tasks/:id/cancel 取消任务
DELETE /api/v1/tasks/:id 删除任务
GET /ws WebSocket 实时进度

测试目录

默认支持以下测试目录:

  • /tmp - 临时目录
  • /data/workspace - 工作空间目录

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors