refactor(cli): move the benchmarkd command to folder

pull/90/head
moonrailgun 2 years ago
parent 3f6c3b08d8
commit 48145a01ee

@ -0,0 +1,11 @@
import { CommandModule } from 'yargs';
import { benchMessageCommand } from './message';
// https://docs.docker.com/engine/api/v1.41/
export const benchmarkCommand: CommandModule = {
command: 'benchmark',
describe: 'Tailchat Benchmark Test',
builder: (yargs) => yargs.command(benchMessageCommand).demandCommand(),
handler(args) {},
};

@ -10,97 +10,89 @@ import ora from 'ora';
import prettyMs from 'pretty-ms';
import filesize from 'filesize';
export const benchCommand: CommandModule = {
command: 'bench',
describe: 'Benchmark',
export const benchMessageCommand: CommandModule = {
command: 'message',
describe:
'Stress testing through Tailchat network requests (suitable for pure business testing)',
builder: (yargs) =>
yargs
.command(
'message',
'Stress testing through Tailchat network requests (suitable for pure business testing)',
(yargs) =>
yargs
.option('groupId', {
describe: 'Group ID',
demandOption: true,
type: 'string',
})
.option('converseId', {
describe: 'Converse ID',
demandOption: true,
type: 'string',
})
.option('userId', {
describe: 'User ID',
demandOption: true,
type: 'string',
})
.option('num', {
describe: 'Test Num',
type: 'number',
default: 100,
})
.option('parallel', {
describe: 'Is Parallel',
type: 'boolean',
default: false,
})
.option('parallelLimit', {
describe: 'Parallel Limit',
type: 'number',
default: Infinity,
}),
async (args) => {
config(); // 加载环境变量
const broker = new TcBroker({
...defaultBrokerConfig,
transporter: process.env.TRANSPORTER,
logger: false,
});
await broker.start();
printSystemInfo();
console.log('===============');
await startBenchmark<number>({
parallel: args.parallel,
parallelLimit: args.parallelLimit,
number: args.num,
task: async (i) => {
const start = process.hrtime();
await broker.call(
'chat.message.sendMessage',
{
converseId: args.converseId,
groupId: args.groupId,
content: `benchmessage ${i + 1}`,
},
{
meta: {
userId: args.userId,
},
}
);
const usage = calcUsage(start);
return usage;
},
onCompleted: (res) => {
console.log(`Test Num: \t${res.length}`);
console.log(`Max Usage: \t${prettyMs(Math.max(...res, 0))}`);
console.log(`Min Usage: \t${prettyMs(Math.min(...res, 0))}`);
console.log(`Average time: \t${prettyMs(_.mean(res))}`);
.option('groupId', {
describe: 'Group ID',
demandOption: true,
type: 'string',
})
.option('converseId', {
describe: 'Converse ID',
demandOption: true,
type: 'string',
})
.option('userId', {
describe: 'User ID',
demandOption: true,
type: 'string',
})
.option('num', {
describe: 'Test Num',
type: 'number',
default: 100,
})
.option('parallel', {
describe: 'Is Parallel',
type: 'boolean',
default: false,
})
.option('parallelLimit', {
describe: 'Parallel Limit',
type: 'number',
default: Infinity,
}),
async handler(args) {
config(); // 加载环境变量
const broker = new TcBroker({
...defaultBrokerConfig,
transporter: process.env.TRANSPORTER,
logger: false,
});
await broker.start();
printSystemInfo();
console.log('===============');
await startBenchmark<number>({
parallel: args.parallel as boolean,
parallelLimit: args.parallelLimit as number,
number: args.num as number,
task: async (i) => {
const start = process.hrtime();
await broker.call(
'chat.message.sendMessage',
{
converseId: args.converseId,
groupId: args.groupId,
content: `benchmessage ${i + 1}`,
},
{
meta: {
userId: args.userId,
},
});
await broker.stop();
}
)
.demandCommand(),
handler() {},
}
);
const usage = calcUsage(start);
return usage;
},
onCompleted: (res) => {
console.log(`Test Num: \t${res.length}`);
console.log(`Max Usage: \t${prettyMs(Math.max(...res, 0))}`);
console.log(`Min Usage: \t${prettyMs(Math.min(...res, 0))}`);
console.log(`Average time: \t${prettyMs(_.mean(res))}`);
},
});
await broker.stop();
},
};
/**

@ -4,7 +4,7 @@ import { createCommand } from './commands/create';
import { connectCommand } from './commands/connect';
import { appCommand } from './commands/app';
import { declarationCommand } from './commands/declaration';
import { benchCommand } from './commands/bench';
import { benchmarkCommand } from './commands/benchmark';
import { dockerCommand } from './commands/docker';
import { usageCommand } from './commands/usage';
import { registryCommand } from './commands/registry';
@ -15,7 +15,7 @@ yargs
.command(createCommand)
.command(connectCommand)
.command(appCommand)
.command(benchCommand)
.command(benchmarkCommand)
.command(declarationCommand)
.command(dockerCommand)
.command(registryCommand)

Loading…
Cancel
Save