Skip to content
Skillv1.0.0

benchmarking

性能基准测试

by chaterm(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from chaterm/terminal-skills (performance/benchmarking/SKILL.md). Install upstream with npx skills add chaterm/terminal-skills --skill benchmarking. Copyright stays with the author.

性能基准测试

概述

压力测试、基准测试工具使用技能。

sysbench

安装

# Debian/Ubuntu
apt install sysbench

# CentOS/RHEL
yum install sysbench

CPU 测试

# 单线程
sysbench cpu run

# 多线程
sysbench cpu --threads=4 run

# 指定时间
sysbench cpu --threads=4 --time=60 run

内存测试

# 顺序读写
sysbench memory run

# 随机读写
sysbench memory --memory-access-mode=rnd run

# 指定大小
sysbench memory --memory-block-size=1M --memory-total-size=10G run

磁盘 IO 测试

# 准备测试文件
sysbench fileio --file-total-size=10G prepare

# 随机读写
sysbench fileio --file-total-size=10G --file-test-mode=rndrw run

# 顺序读
sysbench fileio --file-total-size=10G --file-test-mode=seqrd run

# 清理
sysbench fileio --file-total-size=10G cleanup

MySQL 测试

# 准备数据
sysbench oltp_read_write --mysql-host=localhost --mysql-user=root \
    --mysql-password=pass --mysql-db=test --tables=10 --table-size=100000 prepare

# 运行测试
sysbench oltp_read_write --mysql-host=localhost --mysql-user=root \
    --mysql-password=pass --mysql-db=test --tables=10 --table-size=100000 \
    --threads=16 --time=60 run

# 清理
sysbench oltp_read_write --mysql-host=localhost --mysql-user=root \
    --mysql-password=pass --mysql-db=test cleanup

fio 磁盘测试

基础测试

# 顺序读
fio --name=seqread --rw=read --bs=1M --size=1G --numjobs=1 --runtime=60

# 顺序写
fio --name=seqwrite --rw=write --bs=1M --size=1G --numjobs=1 --runtime=60

# 随机读
fio --name=randread --rw=randread --bs=4k --size=1G --numjobs=4 --runtime=60

# 随机写
fio --name=randwrite --rw=randwrite --bs=4k --size=1G --numjobs=4 --runtime=60

# 混合读写
fio --name=randrw --rw=randrw --bs=4k --size=1G --numjobs=4 --rwmixread=70 --runtime=60

配置文件

# test.fio
[global]
ioengine=libaio
direct=1
runtime=60
time_based

[seqread]
rw=read
bs=1M
size=1G

[randread]
rw=randread
bs=4k
size=1G
numjobs=4
fio test.fio

HTTP 压测

ab (Apache Bench)

# 基础测试
ab -n 1000 -c 100 http://localhost/

# 带 Keep-Alive
ab -n 1000 -c 100 -k http://localhost/

# POST 请求
ab -n 1000 -c 100 -p data.json -T application/json http://localhost/api

wrk

# 基础测试
wrk -t4 -c100 -d30s http://localhost/

# 带脚本
wrk -t4 -c100 -d30s -s post.lua http://localhost/api

hey

# 基础测试
hey -n 1000 -c 100 http://localhost/

# 指定时间
hey -z 30s -c 100 http://localhost/

# POST 请求
hey -n 1000 -c 100 -m POST -d '{"key":"value"}' http://localhost/api

网络测试

iperf3

# 服务端
iperf3 -s

# 客户端
iperf3 -c server_ip

# UDP 测试
iperf3 -c server_ip -u -b 1G

# 双向测试
iperf3 -c server_ip -d

# 多线程
iperf3 -c server_ip -P 4

netperf

# 服务端
netserver

# TCP 吞吐
netperf -H server_ip

# TCP 延迟
netperf -H server_ip -t TCP_RR

常见场景

场景 1:服务器基准测试

#!/bin/bash
echo "=== CPU 测试 ==="
sysbench cpu --threads=$(nproc) --time=30 run

echo "=== 内存测试 ==="
sysbench memory --threads=$(nproc) --time=30 run

echo "=== 磁盘测试 ==="
fio --name=test --rw=randrw --bs=4k --size=1G --runtime=30 --time_based

场景 2:数据库基准

#!/bin/bash
# MySQL OLTP 测试
sysbench oltp_read_write \
    --mysql-host=localhost \
    --mysql-user=root \
    --mysql-password=pass \
    --mysql-db=sbtest \
    --tables=10 \
    --table-size=100000 \
    --threads=16 \
    --time=300 \
    --report-interval=10 \
    run

结果解读

指标 说明
TPS 每秒事务数
QPS 每秒查询数
IOPS 每秒 IO 操作数
延迟 响应时间
吞吐量 数据传输速率

故障排查

# 检查系统负载
uptime
vmstat 1

# 检查 IO
iostat -x 1

# 检查网络
sar -n DEV 1

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/chaterm-terminal-skills-benchmarking/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

chaterm-terminal-skills-benchmarking.ocm.jsonjson
{
  "ocm": "1",
  "id": "chaterm-terminal-skills-benchmarking",
  "kind": "skill",
  "name": "benchmarking",
  "description": "性能基准测试",
  "publisher": "chaterm",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "performance",
      "benchmark",
      "stress",
      "load-test",
      "sysbench",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "性能基准测试"
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/chaterm/terminal-skills",
      "path": "performance/benchmarking/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/chaterm/terminal-skills/blob/HEAD/performance/benchmarking/SKILL.md",
      "key": "chaterm/terminal-skills/performance/benchmarking/SKILL.md"
    }
  },
  "instructions": "# 性能基准测试\n\n## 概述\n压力测试、基准测试工具使用技能。\n\n## sysbench\n\n### 安装\n```bash\n# Debian/Ubuntu\napt install sysbench\n\n# CentOS/RHEL\nyum install sysbench\n```\n\n### CPU 测试\n```bash\n# 单线程\nsysbench cpu run\n\n# 多线程\nsysbench cpu --threads=4 run\n\n# 指定时间\nsysbench cpu --threads=4 --time=60 run\n```\n\n### 内存测试\n```bash\n# 顺序读写\nsysbench memory run\n\n# 随机读写\nsysbench memory --memory-access-mode=rnd run\n\n# 指定大小\nsysbench memory --memory-block-size=1M --memory-total-size=10G run\n```\n\n### 磁盘 IO 测试\n```bash\n# 准备测试文件\nsysbench fileio --file-total-size=10G prepare\n\n# 随机读写\nsysbench fileio --file-total-size=10G --file-test-mode=rndrw run\n\n# 顺",
  "cost": {
    "context_tokens": 874
  }
}

Fetch it by URL: GET /api/v1/registry/chaterm-terminal-skills-benchmarking/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.