MCPcopy Create free account
hub / github.com/msgbyte/tailchat / handler

Function handler

apps/cli/src/commands/benchmark/message.ts:49–95  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

47 default: Infinity,
48 }),
49 async handler(args) {
50 config(); // 加载环境变量
51
52 const broker = new TcBroker({
53 ...defaultBrokerConfig,
54 transporter: process.env.TRANSPORTER,
55 logger: false,
56 });
57 await broker.start();
58
59 printSystemInfo();
60
61 console.log('===============');
62
63 await startBenchmark<number>({
64 parallel: args.parallel as boolean,
65 parallelLimit: args.parallelLimit as number,
66 number: args.num as number,
67 task: async (i) => {
68 const start = process.hrtime();
69 await broker.call(
70 'chat.message.sendMessage',
71 {
72 converseId: args.converseId,
73 groupId: args.groupId,
74 content: `benchmessage ${i + 1}`,
75 },
76 {
77 meta: {
78 userId: args.userId,
79 },
80 }
81 );
82 const usage = calcUsage(start);
83
84 return usage;
85 },
86 onCompleted: (res) => {
87 console.log(`Test Num: \t${res.length}`);
88 console.log(`Max Usage: \t${prettyMs(Math.max(...res, 0))}`);
89 console.log(`Min Usage: \t${prettyMs(Math.min(...res, 0))}`);
90 console.log(`Average time: \t${prettyMs(_.mean(res))}`);
91 },
92 });
93
94 await broker.stop();
95 },
96};
97
98/**

Callers

nothing calls this directly

Calls 6

printSystemInfoFunction · 0.85
calcUsageFunction · 0.85
startMethod · 0.80
stopMethod · 0.80
logMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected