12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- const { Subscription, Node } = require('./src/models');
- const MultiSubscriptionManager = require('./src/core/multiSubscriptionManager');
- async function testPerformance() {
- try {
- console.log('=== 性能测试 ===');
-
- // 创建测试订阅
- const testSubscription = await Subscription.create({
- name: '性能测试订阅',
- url: 'http://so.xfxssr.me/api/v1/client/subscribe?token=7854d59f38ac51700730b9e782c5160c',
- description: '用于测试性能的订阅',
- speedTestConfig: {
- testCount: 3,
- timeout: 10000,
- testUrls: ['https://www.google.com'],
- speedTestEnabled: true
- },
- notifyConfig: {
- enabled: true,
- notifyOnSpeedTest: true,
- notifyOnNodeUpdate: true,
- webhookUrl: '',
- emailConfig: null
- }
- });
-
- console.log('✅ 创建测试订阅成功');
- // 创建大量测试节点
- const nodeCount = 50;
- console.log(`\n创建 ${nodeCount} 个测试节点...`);
-
- const testNodes = [];
- for (let i = 1; i <= nodeCount; i++) {
- testNodes.push({
- name: `性能测试节点${i}`,
- type: 'ss',
- server: `server${i}.example.com`,
- port: 443 + (i % 100),
- method: 'aes-256-gcm',
- password: `password${i}`,
- subscriptionId: testSubscription.id,
- isActive: true,
- status: 'offline'
- });
- }
- // 批量创建节点
- const startTime = Date.now();
- await Node.bulkCreate(testNodes);
- const createTime = Date.now() - startTime;
-
- console.log(`✅ 批量创建 ${nodeCount} 个节点完成,耗时: ${createTime}ms`);
- // 更新订阅节点数量
- await testSubscription.update({
- nodeCount: nodeCount,
- lastUpdateTime: new Date()
- });
- // 测试多订阅管理器性能
- console.log('\n测试多订阅管理器性能...');
- const manager = new MultiSubscriptionManager();
-
- const managerStartTime = Date.now();
- const activeSubscriptions = await manager.getActiveSubscriptions();
- const managerTime = Date.now() - managerStartTime;
-
- console.log(`✅ 获取活跃订阅完成,耗时: ${managerTime}ms`);
- console.log(` 活跃订阅数量: ${activeSubscriptions.length}`);
- // 测试状态获取性能
- const statusStartTime = Date.now();
- const status = await manager.getStatus();
- const statusTime = Date.now() - statusStartTime;
-
- console.log(`✅ 获取状态完成,耗时: ${statusTime}ms`);
- // 清理测试数据
- console.log('\n清理测试数据...');
- await testSubscription.destroy();
- console.log('✅ 测试数据清理完成');
- console.log('\n=== 性能测试完成 ===');
- console.log(`总结:`);
- console.log(` - 批量创建 ${nodeCount} 个节点: ${createTime}ms`);
- console.log(` - 获取活跃订阅: ${managerTime}ms`);
- console.log(` - 获取状态: ${statusTime}ms`);
-
- } catch (error) {
- console.error('❌ 性能测试失败:', error.message);
- }
- }
- // 运行测试
- testPerformance();
|