Spaces:
Running
Running
| /** | |
| * 并发压力测试脚本 | |
| * 运行方式: node stress-test.js | |
| */ | |
| const fetchTest = async () => { | |
| const url = 'http://localhost:7863/api/debug/stress-test'; | |
| const payload = { | |
| count: 10, // 总任务数 | |
| concurrency: 3 // 最大并发数 | |
| }; | |
| console.log('🚀 正在启动压力测试...'); | |
| console.log(`📊 计划: 处理 ${payload.count} 个任务,限制并发为 ${payload.concurrency}`); | |
| try { | |
| const response = await fetch(url, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify(payload) | |
| }); | |
| const data = await response.json(); | |
| if (data.success) { | |
| console.log('\n✅ 压力测试完成!'); | |
| console.log(`⏱️ 总耗时: ${data.duration}`); | |
| console.log(`📉 平均每任务耗时: ${data.avgTime}`); | |
| console.log(`📦 最终队列状态:`, data.status); | |
| } else { | |
| console.error('❌ 测试失败:', data.error); | |
| } | |
| } catch (err) { | |
| console.error('❌ 无法连接到服务器,请确保服务器正在运行:', err.message); | |
| } | |
| }; | |
| fetchTest(); | |