# ============================================================================ # 年会现场真实场景压测 - 节目投票瞬间爆发 # 场景:节目结束后主持人宣布开始投票,100人同时打开页面,每人投7票 # ============================================================================ # # 运行方式: # artillery run vote-real-scenario.yaml -e live # # ============================================================================ config: target: "http://127.0.0.1:3000" # 性能阈值 ensure: p95: 500 maxErrorRate: 1 # Socket.IO 配置 - 强制 WebSocket socketio: transports: ["websocket"] path: "/socket.io" extraHeaders: Origin: "http://localhost:5174" # 处理器脚本 processor: "./vote-processor.cjs" # 7个节目ID和7个奖项票种(一一对应) variables: programIds: - "p1" - "p2" - "p3" - "p4" - "p5" - "p6" - "p7" ticketTypes: - "creative" - "visual" - "atmosphere" - "performance" - "teamwork" - "popularity" - "potential" # 环境配置 environments: # 现场真实场景 - 100人同时涌入 live: target: "http://127.0.0.1:3000" phases: # 阶段1: 瞬间爆发 - 100人同时进入(主持人宣布投票开始) - name: "投票开始!100人同时进入" duration: 2 arrivalRate: 50 # 2秒100人 = 50人/秒,模拟瞬间爆发 # 阶段2: 投票高峰期 - 持续投票 - name: "投票高峰期" duration: 45 arrivalRate: 5 # 维持连接,持续投票 # 阶段3: 投票结束 - name: "投票结束" duration: 5 arrivalRate: 2 # ============================================================================ # 测试场景定义 - 模拟三种投票速度的用户 # ============================================================================ scenarios: # 场景1: 快速投票者 (30%) - 2-3秒投完7票,手速极快 - name: "快速投票者" weight: 3 engine: socketio flow: - function: "generateUserId" - emit: channel: "connection:join" data: userId: "{{ userId }}" userName: "快投-{{ userId }}" role: "user" department: "快速组" # 快速投7票(每票间隔 0.2-0.4 秒) - loop: - function: "selectSequentialTicket" - function: "selectRandomProgram" - emit: channel: "vote:submit" data: candidateId: "{{ selectedProgram }}" category: "{{ selectedTicket }}" localId: "{{ $uuid }}" - think: 0.3 count: 7 - think: 1 # 场景2: 正常投票者 (50%) - 10-15秒投完7票,正常速度 - name: "正常投票者" weight: 5 engine: socketio flow: - function: "generateUserId" - emit: channel: "connection:join" data: userId: "{{ userId }}" userName: "正常-{{ userId }}" role: "user" department: "正常组" # 正常速度投7票(每票间隔 1-2 秒,看节目、思考) - loop: - function: "selectSequentialTicket" - function: "selectRandomProgram" - emit: channel: "vote:submit" data: candidateId: "{{ selectedProgram }}" category: "{{ selectedTicket }}" localId: "{{ $uuid }}" - function: "randomNormalDelay" - think: "{{ normalDelay }}" count: 7 - think: 3 # 场景3: 慢速投票者 (20%) - 30-40秒投完7票,犹豫不决型 - name: "慢速投票者" weight: 2 engine: socketio flow: - function: "generateUserId" - emit: channel: "connection:join" data: userId: "{{ userId }}" userName: "慢投-{{ userId }}" role: "user" department: "慢速组" # 先观望 5-10 秒 - function: "randomLongDelay" - think: "{{ longDelay }}" # 慢速投7票(每票间隔 3-5 秒) - loop: - function: "selectSequentialTicket" - function: "selectRandomProgram" - emit: channel: "vote:submit" data: candidateId: "{{ selectedProgram }}" category: "{{ selectedTicket }}" localId: "{{ $uuid }}" - function: "randomSlowDelay" - think: "{{ slowDelay }}" count: 7 - think: 5