signal-desktop/ts/test-mock/benchmarks/startup_bench.ts

136 lines
3.6 KiB
TypeScript
Raw Normal View History

// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { ReceiptType } from '@signalapp/mock-server';
import { omit } from 'lodash';
import { debug, Bootstrap, MAX_CYCLES } from './fixtures';
import { type RegressionSample } from '../bootstrap';
const INITIAL_MESSAGE_COUNT = 1000;
const FINAL_MESSAGE_COUNT = 5000;
const ENABLE_RECEIPTS = Boolean(process.env.ENABLE_RECEIPTS);
Bootstrap.regressionBenchmark(
async ({ bootstrap, value: messageCount }): Promise<RegressionSample> => {
await bootstrap.linkAndClose();
const { server, contacts, phone, desktop } = bootstrap;
2023-03-13 16:41:47 -07:00
// Generate messages
const messagePromises = new Array<Promise<Buffer>>();
debug('started generating messages');
for (let i = 0; i < messageCount; i += 1) {
2023-03-13 16:41:47 -07:00
const contact = contacts[Math.floor(i / 2) % contacts.length];
const direction = i % 2 ? 'message' : 'reply';
2023-03-13 16:41:47 -07:00
const messageTimestamp = bootstrap.getTimestamp();
2023-03-13 16:41:47 -07:00
if (direction === 'message') {
messagePromises.push(
2023-03-13 16:41:47 -07:00
contact.encryptText(
desktop,
`Ping from mock server ${i + 1} / ${messageCount}`,
{
timestamp: messageTimestamp,
2023-03-13 16:41:47 -07:00
sealed: true,
}
)
);
if (ENABLE_RECEIPTS) {
messagePromises.push(
2023-03-13 16:41:47 -07:00
phone.encryptSyncRead(desktop, {
timestamp: bootstrap.getTimestamp(),
2023-03-13 16:41:47 -07:00
messages: [
{
2023-08-16 22:54:39 +02:00
senderAci: contact.device.aci,
2023-03-13 16:41:47 -07:00
timestamp: messageTimestamp,
},
],
})
);
}
2023-03-13 16:41:47 -07:00
continue;
}
messagePromises.push(
phone.encryptSyncSent(
desktop,
`Pong from mock server ${i + 1} / ${messageCount}`,
2023-03-13 16:41:47 -07:00
{
timestamp: messageTimestamp,
2023-08-16 22:54:39 +02:00
destinationServiceId: contact.device.aci,
2023-03-13 16:41:47 -07:00
}
)
);
if (ENABLE_RECEIPTS) {
messagePromises.push(
contact.encryptReceipt(desktop, {
timestamp: bootstrap.getTimestamp(),
messageTimestamps: [messageTimestamp],
type: ReceiptType.Delivery,
})
);
messagePromises.push(
contact.encryptReceipt(desktop, {
timestamp: bootstrap.getTimestamp(),
messageTimestamps: [messageTimestamp],
type: ReceiptType.Read,
})
);
}
2023-03-13 16:41:47 -07:00
}
2023-03-13 16:41:47 -07:00
debug('ended generating messages');
2023-03-13 16:41:47 -07:00
const messages = await Promise.all(messagePromises);
2023-03-13 16:41:47 -07:00
// Open the flood gates
{
debug('got synced, sending messages');
2023-03-13 16:41:47 -07:00
// Queue all messages
const queue = async (): Promise<void> => {
await Promise.all(
messages.map(message => {
return server.send(desktop, message);
})
);
};
const run = async () => {
2023-03-13 16:41:47 -07:00
const app = await bootstrap.startApp();
const appLoadedInfo = await app.waitUntilLoaded();
2025-04-14 14:29:02 -07:00
if (!(await app.waitForPreloadCacheHit())) {
throw new Error('Preload cache miss');
}
2023-03-13 16:41:47 -07:00
await app.close();
return appLoadedInfo;
2023-03-13 16:41:47 -07:00
};
const [, info] = await Promise.all([queue(), run()]);
2025-04-03 15:24:35 -07:00
const { loadTime, preloadTime, preloadCompileTime, connectTime } = info;
const messagesDuration =
loadTime - preloadTime - preloadCompileTime - connectTime;
2025-02-25 11:21:36 -08:00
return {
messagesDuration,
metrics: omit(info, 'messagesPerSec', 'loadTime'),
};
}
},
{
fromValue: INITIAL_MESSAGE_COUNT,
toValue: FINAL_MESSAGE_COUNT,
maxCycles: MAX_CYCLES,
}
);