SPB Git

Repository Public

load.ts 2.2 KB 44 lines typescript

1// Load test: N accounts in one encrypted group plus pairwise conversations, real server, real crypto.2// Usage: tsx tests/load.ts [users=16] [messagesPerUser=30]3import { Actor, issueBootstrap, sql, startServer, stopServer, tokenOf, until } from "./harness"45const N = Number(process.argv[2] ?? 16), M = Number(process.argv[3] ?? 30)6await startServer()7const admin = new Actor("admin")8await admin.register(await issueBootstrap(), true)9await admin.setup()10const users: Actor[] = [admin]11const t0 = Date.now()12for (let i = 1; i < N; i++) {13  const u = new Actor(`user${i}`)14  const inv = await admin.t.request<{ url: string }>("POST", "/api/admin/invitations", {})15  await u.register(tokenOf(inv.url))16  await u.setup()17  users.push(u)18}19const tSetup = Date.now() - t020const t1 = Date.now()21const group = await admin.engine.createConversation("group", users.slice(1).map((u) => u.me.id), "Load")22await until(() => users.every((u) => !!u.engine.convs.get(group)?.state), "everyone joined", 60000)23const tJoin = Date.now() - t124const t2 = Date.now()25await Promise.all(users.map(async (u, i) => {26  for (let k = 0; k < M; k++) await u.engine.send(group, { t: "text", body: `m ${i}/${k} ${"x".repeat(120)}` })27}))28const total = N * M29await until(() => users.every((u) => u.texts(group).length === total), "every device decrypted every message", 180000)30const tMsg = Date.now() - t231// ordering: every device shows the same sequence32const ref = users[0].conv(group).messages.filter((m) => m.kind === "text").map((m) => m.id).join()33const consistent = users.every((u) => u.conv(group).messages.filter((m) => m.kind === "text").map((m) => m.id).join() === ref)34const [{ n }] = await sql`select count(*)::int as n from messages where conversation_id = ${group} and kind = 'app'`35console.log(JSON.stringify({36  users: N, messages_sent: total, deliveries_decrypted: total * (N - 1), stored_ciphertexts: n,37  setup_ms_per_account: Math.round(tSetup / (N - 1)), group_join_ms: tJoin, messaging_ms: tMsg,38  sends_per_second: Math.round((total / tMsg) * 1000), decryptions_per_second: Math.round(((total * (N - 1)) / tMsg) * 1000),39  same_order_on_every_device: consistent,40}, null, 2))41for (const u of users) u.engine.stop()42await stopServer()43process.exit(consistent ? 0 : 1)44
Files main
Menu

Theme