agentleFS
28672032962867203296/hermes-agent/skills/software-development/load-testing/SKILL.md

load-testing

Skill0 starsChanged 3 months agoMITView on GitHub

压力测试:k6脚本、Locust、QPS目标、瓶颈定位.

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use frontend-design.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • BlockSkill

    frontend-design

    Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

    Also in 3 projects that use this

The file

Files
SKILL.md

压力测试

为什么压测

代码在1个用户时正常 ≠ 1000个用户时正常

压测回答:
- 系统能撑多少 QPS?
- 瓶颈在哪(CPU/内存/DB/网络)?
- 什么时候开始崩?

k6(推荐,轻量)

// test.js
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '30s', target: 50 },  // 30秒内涨到50并发
    { duration: '1m',  target: 50 },  // 保持50并发1分钟
    { duration: '30s', target: 0 },   // 30秒内降到0
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'], // 95%请求 < 500ms
    http_req_failed: ['rate<0.01'],   // 错误率 < 1%
  },
};

export default function () {
  const res = http.get('http://localhost:8000/api/users');
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 500ms': (r) => r.timings.duration < 500,
  });
  sleep(1);
}
k6 run test.js

Locust(Python 原生)

from locust import HttpUser, task, between

class WebsiteUser(HttpUser):
    wait_time = between(1, 3)

    @task(3)  # 权重3
    def get_users(self):
        self.client.get("/api/users")

    @task(1)  # 权重1
    def create_user(self):
        self.client.post("/api/users", json={"name": "test"})
locust -f test.py --host http://localhost:8000
# 打开 http://localhost:8089 看实时图表

压测策略

1. 基准测试:1个用户,看单次响应时间
2. 负载测试:逐步加并发,找拐点
3. 压力测试:超过预期的并发,看怎么崩的
4. 浸泡测试:中等负载跑 24 小时,找内存泄漏

不要在生产环境压测!用 staging。

关键指标

QPS(每秒请求数):系统吞吐量
P50/P95/P99 延迟:50%/95%/99% 请求的响应时间
错误率:失败的请求占比
并发用户数:同时发请求的用户数

瓶颈定位

QPS 上不去?依次检查:
1. CPU 满了?→ 代码优化 / 加机器
2. 数据库慢?→ 加索引 / 读写分离 / 缓存
3. 网络瓶颈?→ 压缩 / CDN
4. 代码阻塞?→ 异步 / 连接池
5. 内存泄漏?→ 长时间浸泡测试

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.