Files
Home-Care/hss-home-service/website/tests/load/load-test.mjs
comclib 01e1034cc1 feat: 全系统优化 — 并发控制 + 冗余清理 + 数据流修复 + 全面测试
核心修复:
- 状态机加 SELECT FOR UPDATE 行锁,消除并发竞态
- hss_md_staff 加 role 列,登录从数据库读取真实角色
- 申请重复校验排除自身,全流程 20 步闭环通过
- 派单 SQL 修复 + 支付状态机过渡 + 完成服务 plan_item_id 修复

并发控制新增:
- RedisLockService (SET NX PX + Lua 安全解锁)
- RateLimiterService (Redis 滑动窗口 + API 拦截器)
- TransactionIsolationConfig (SERIALIZABLE for 支付回调)
- MqttPublisher (异步队列 + JDK TCP 探测)
- ObjectStorageService (AWS SigV4 预签名, 纯 JDK)

冗余清理:
- 删除 6 个死代码文件 (~620 行)
- hutool-all → JDK MessageDigest, 去 MapStruct, 去 jsr310
- haversine 提取到 GeoUtil, count/round 提取到 JdbcUtil
- 创建 platform layout 组件

前端修复:
- 登录页移除角色选择器, 由后端 JWT 返回
- 移除 ClientOnly 包裹, 页面正常渲染
- SPA fallback Nginx 配置修复

Docker: 运行时镜像 eclipse-temurin:17-jre-jammy (缩小 ~300MB)

文档: 新增系统实现与修复报告.md

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 11:48:07 +08:00

66 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Node.js 并发负载测试(替代 k6
const BASE = 'http://172.31.12.249:18080/api/hss';
const H = { 'Content-Type': 'application/json', 'X-Tenant-Id': '1', 'X-Org-Id': '1', 'X-User-Role': 'ADMIN' };
let total = 0, passed = 0, failed = 0;
const start = Date.now();
const startMem = process.memoryUsage().heapUsed;
async function req(path, method = 'GET', body = null) {
const headers = { ...H, 'Idempotency-Key': 'load-' + Math.random().toString(36).slice(2,10) };
const r = await fetch(BASE + path, { method, headers, body: body ? JSON.stringify(body) : undefined });
return r.status;
}
// 阶段1: 阶梯负载 (5 → 20 → 0 并发)
const stages = [
{ duration: 5000, concurrency: 5 },
{ duration: 10000, concurrency: 10 },
{ duration: 15000, concurrency: 20 },
{ duration: 10000, concurrency: 10 },
{ duration: 5000, concurrency: 5 },
];
async function runStage(concurrency, durationMs) {
const endTime = Date.now() + durationMs;
const tasks = [];
while (Date.now() < endTime) {
for (let i = 0; i < concurrency; i++) {
tasks.push((async () => {
total++;
try {
const paths = ['/admin/dashboard', '/analytics/summary', '/master/service-items',
'/applications?page=1&size=10', '/admin/work-orders?page=1&size=10'];
const status = await req(paths[Math.floor(Math.random() * paths.length)]);
if (status === 200) passed++; else failed++;
} catch (e) { failed++; }
})());
}
if (tasks.length > 500) {
await Promise.all(tasks.splice(0, 200));
}
await new Promise(r => setTimeout(r, 1000 / concurrency));
}
await Promise.all(tasks);
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
console.log(` [${elapsed}s] concurrency=${concurrency} passed=${passed} failed=${failed} total=${total}`);
}
async function main() {
console.log('=== 负载测试:阶梯并发 5→10→20→10→5 ===\n');
for (const s of stages) {
await runStage(s.concurrency, s.duration);
}
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
const rps = (total / elapsed).toFixed(1);
const passRate = total > 0 ? (passed / total * 100).toFixed(1) : '0';
const memUsed = ((process.memoryUsage().heapUsed - startMem) / 1024 / 1024).toFixed(1);
console.log(`\n=== 结果 ===`);
console.log(`总请求: ${total} 通过: ${passed} 失败: ${failed} 通过率: ${passRate}%`);
console.log(`耗时: ${elapsed}s RPS: ${rps} 内存: ${memUsed}MB`);
}
main().catch(console.error);