2022-02-11 22:32:51 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
/* eslint-disable no-await-in-loop, no-console */
|
|
|
|
|
|
|
|
import { ReceiptType } from '@signalapp/mock-server';
|
|
|
|
|
2023-07-20 22:37:56 +00:00
|
|
|
import { debug, Bootstrap, RUN_COUNT } from './fixtures';
|
|
|
|
import { stats } from '../../util/benchmark/stats';
|
2022-02-11 22:32:51 +00:00
|
|
|
|
|
|
|
const MESSAGE_BATCH_SIZE = 1000; // messages
|
|
|
|
|
|
|
|
const ENABLE_RECEIPTS = Boolean(process.env.ENABLE_RECEIPTS);
|
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
Bootstrap.benchmark(async (bootstrap: Bootstrap): Promise<void> => {
|
2022-02-11 22:32:51 +00:00
|
|
|
await bootstrap.linkAndClose();
|
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const { server, contacts, phone, desktop } = bootstrap;
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const messagesPerSec = new Array<number>();
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
for (let runId = 0; runId < RUN_COUNT; runId += 1) {
|
|
|
|
// Generate messages
|
|
|
|
const messagePromises = new Array<Promise<Buffer>>();
|
|
|
|
debug('started generating messages');
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
for (let i = 0; i < MESSAGE_BATCH_SIZE; i += 1) {
|
|
|
|
const contact = contacts[Math.floor(i / 2) % contacts.length];
|
|
|
|
const direction = i % 2 ? 'message' : 'reply';
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const messageTimestamp = bootstrap.getTimestamp();
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
if (direction === 'message') {
|
2022-02-11 22:32:51 +00:00
|
|
|
messagePromises.push(
|
2023-03-13 23:41:47 +00:00
|
|
|
contact.encryptText(
|
2022-02-11 22:32:51 +00:00
|
|
|
desktop,
|
2023-03-13 23:41:47 +00:00
|
|
|
`Ping from mock server ${i + 1} / ${MESSAGE_BATCH_SIZE}`,
|
2022-02-11 22:32:51 +00:00
|
|
|
{
|
|
|
|
timestamp: messageTimestamp,
|
2023-03-13 23:41:47 +00:00
|
|
|
sealed: true,
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ENABLE_RECEIPTS) {
|
|
|
|
messagePromises.push(
|
2023-03-13 23:41:47 +00:00
|
|
|
phone.encryptSyncRead(desktop, {
|
2022-02-11 22:32:51 +00:00
|
|
|
timestamp: bootstrap.getTimestamp(),
|
2023-03-13 23:41:47 +00:00
|
|
|
messages: [
|
|
|
|
{
|
2023-08-16 20:54:39 +00:00
|
|
|
senderAci: contact.device.aci,
|
2023-03-13 23:41:47 +00:00
|
|
|
timestamp: messageTimestamp,
|
|
|
|
},
|
|
|
|
],
|
2022-02-11 22:32:51 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2023-03-13 23:41:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
messagePromises.push(
|
|
|
|
phone.encryptSyncSent(
|
|
|
|
desktop,
|
|
|
|
`Pong from mock server ${i + 1} / ${MESSAGE_BATCH_SIZE}`,
|
|
|
|
{
|
|
|
|
timestamp: messageTimestamp,
|
2023-08-16 20:54:39 +00:00
|
|
|
destinationServiceId: contact.device.aci,
|
2023-03-13 23:41:47 +00: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,
|
|
|
|
})
|
|
|
|
);
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
2023-03-13 23:41:47 +00:00
|
|
|
}
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
debug('ended generating messages');
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const messages = await Promise.all(messagePromises);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
// Open the flood gates
|
|
|
|
{
|
|
|
|
debug('got synced, sending messages');
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
// Queue all messages
|
|
|
|
const queue = async (): Promise<void> => {
|
|
|
|
await Promise.all(
|
|
|
|
messages.map(message => {
|
|
|
|
return server.send(desktop, message);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
const run = async (): Promise<void> => {
|
|
|
|
const app = await bootstrap.startApp();
|
|
|
|
const appLoadedInfo = await app.waitUntilLoaded();
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
console.log('run=%d info=%j', runId, appLoadedInfo);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
messagesPerSec.push(appLoadedInfo.messagesPerSec);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
await app.close();
|
|
|
|
};
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
await Promise.all([queue(), run()]);
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
2023-03-13 23:41:47 +00:00
|
|
|
}
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-03-13 23:41:47 +00:00
|
|
|
// Compute human-readable statistics
|
|
|
|
if (messagesPerSec.length !== 0) {
|
|
|
|
console.log('stats info=%j', { messagesPerSec: stats(messagesPerSec) });
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
2023-03-13 23:41:47 +00:00
|
|
|
});
|