Files
lotteryLaravel/scripts/perf/bet-qps.js
kang e27a00f260 feat: 更新玩法配置管理,简化字段并增强功能
- 将玩法相关的显示名称字段统一为 `display_name`,移除多语言字段。
- 在 `PlayTypePatchController` 中新增即时切换玩法开关的功能,并推送大厅更新。
- 优化多个控制器和服务中的权限检查与数据处理逻辑,提升代码可读性与维护性。
2026-05-25 14:34:24 +08:00

76 lines
1.8 KiB
JavaScript

import http from 'k6/http';
import { check, sleep } from 'k6';
import { Counter, Trend } from 'k6/metrics';
const okLatency = new Trend('place_ok_latency', true);
const okCount = new Counter('place_ok_total');
const baseUrl = __ENV.BASE_URL;
const playerId = __ENV.PLAYER_ID;
const drawNo = __ENV.DRAW_NO;
if (!baseUrl || !playerId || !drawNo) {
throw new Error('Set BASE_URL, PLAYER_ID, DRAW_NO');
}
export const options = {
scenarios: {
bet_ramp: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '30s', target: 200 },
{ duration: '60s', target: 1000 },
{ duration: '30s', target: 1000 },
{ duration: '15s', target: 0 },
],
gracefulRampDown: '10s',
},
},
thresholds: {
http_req_failed: ['rate<0.05'],
http_req_duration: ['p(99)<200'],
place_ok_latency: ['p(99)<200'],
place_ok_total: ['count>30000'],
},
};
function payload(vu, iter) {
const n = String(1000 + ((vu + iter) % 9000)).padStart(4, '0');
return JSON.stringify({
draw_id: drawNo,
currency_code: 'NPR',
client_trace_id: `k6-${__VU}-${__ITER}-${Date.now()}`,
lines: [{ number: n, play_code: 'big', amount: 10 }],
});
}
export default function () {
const res = http.post(`${baseUrl}/api/v1/ticket/place`, payload(__VU, __ITER), {
headers: {
Authorization: `Bearer dev:${playerId}`,
'Content-Type': 'application/json',
Accept: 'application/json',
},
tags: { name: 'ticket_place' },
});
const ok = check(res, {
'status 200': (r) => r.status === 200,
'code success': (r) => {
try {
return r.json('code') === 0;
} catch {
return false;
}
},
});
if (ok) {
okLatency.add(res.timings.duration);
okCount.add(1);
}
sleep(0.01);
}