/** * k6 压测全局配置文件 * 直播论坛项目 */ // API 基础地址 export const BASE_URL = 'http://175.27.168.122:83'; // ============================================ // 压测参数配置 // ============================================ // 场景一:普通用户浏览(读操作为主) export const BROWSE_OPTIONS = { // 阶梯式压力测试 stages: [ { duration: '30s', target: 50 }, // 30秒内爬升到50个用户 { duration: '1m', target: 100 }, // 1分钟爬升到100个用户 { duration: '2m', target: 100 }, // 保持100个用户持续2分钟 { duration: '1m', target: 200 }, // 1分钟爬升到200个用户 { duration: '2m', target: 200 }, // 保持200个用户持续2分钟 { duration: '30s', target: 0 }, // 30秒内降到0 ], // 性能阈值 thresholds: { http_req_duration: ['p(95)<500', 'p(99)<1000'], // 95%请求<500ms, 99%<1000ms http_req_failed: ['rate<0.05'], // 错误率<5% http_reqs: ['rate>100'], // QPS>100 }, }; // 场景二:活跃用户互动(读写混合) export const ACTIVE_OPTIONS = { stages: [ { duration: '30s', target: 30 }, // 30秒内爬升到30个用户 { duration: '1m', target: 50 }, // 1分钟爬升到50个用户 { duration: '2m', target: 50 }, // 保持50个用户持续2分钟 { duration: '1m', target: 100 }, // 1分钟爬升到100个用户 { duration: '2m', target: 100 }, // 保持100个用户持续2分钟 { duration: '30s', target: 0 }, // 30秒内降到0 ], thresholds: { http_req_duration: ['p(95)<800', 'p(99)<1500'], // 写操作允许更长时间 http_req_failed: ['rate<0.10'], // 错误率<10%(写操作可能有冲突) http_reqs: ['rate>50'], // TPS>50 }, }; // 场景三:单接口极限压测 export const SINGLE_API_OPTIONS = { stages: [ { duration: '30s', target: 100 }, // 快速爬升 { duration: '1m', target: 300 }, // 继续增加压力 { duration: '2m', target: 500 }, // 高压持续 { duration: '1m', target: 800 }, // 极限压力 { duration: '2m', target: 800 }, // 保持极限 { duration: '30s', target: 0 }, // 缓慢释放 ], thresholds: { http_req_duration: ['p(95)<300', 'p(99)<500'], http_req_failed: ['rate<0.01'], // 单接口要求更严格 http_reqs: ['rate>500'], // 目标QPS>500 }, }; // ============================================ // 快速测试配置(用于调试) // ============================================ export const QUICK_TEST_OPTIONS = { vus: 10, duration: '30s', thresholds: { http_req_duration: ['p(95)<1000'], http_req_failed: ['rate<0.20'], }, }; // ============================================ // 请求超时配置 // ============================================ export const HTTP_TIMEOUT = '30s'; // ============================================ // 思考时间配置(模拟真实用户行为) // ============================================ export const THINK_TIME = { min: 1, // 最小等待时间(秒) max: 3, // 最大等待时间(秒) }; // ============================================ // 测试数据配置 // ============================================ export const TEST_DATA = { // 帖子分页 pageSize: 10, // 评论分页 commentPageSize: 10, // 榜单数量 rankingLimit: 9, // 分类代码 category: 'entertainment', };