-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add better summaries to the stress tests (#23)
count up the number of joins each client receives for each channel. this should let us know if they failed to sync any encryption keys
- Loading branch information
Showing
7 changed files
with
135 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
import { dlogger } from '@river-build/dlog' | ||
import { check, dlogger, shortenHexString } from '@river-build/dlog' | ||
import { StressClient } from '../../utils/stressClient' | ||
import { ChatConfig } from './types' | ||
import { getSystemInfo } from '../../utils/systemInfo' | ||
import { channelMessagePostWhere } from '../../utils/timeline' | ||
import { isDefined } from '@river/sdk' | ||
import { makeCodeBlock } from '../../utils/messages' | ||
|
||
export async function sumarizeChat(client: StressClient, cfg: ChatConfig) { | ||
export async function sumarizeChat(localClients: StressClient[], cfg: ChatConfig) { | ||
const logger = dlogger('stress:sumarizeChat') | ||
|
||
logger.log('sumarizeChat', client.connection.userId) | ||
const announceChannelId = cfg.announceChannelId | ||
const defaultChannel = await client.streamsClient.waitForStream(announceChannelId) | ||
// find the message in the default channel that contains the session id, emoji it | ||
const message = await client.waitFor( | ||
() => | ||
defaultChannel.view.timeline.find( | ||
channelMessagePostWhere((value) => value.body.includes(cfg.sessionId)), | ||
), | ||
{ interval: 1000, timeoutMs: cfg.waitForChannelDecryptionTimeoutMs }, | ||
const processLeadClient = localClients[0] | ||
logger.log('sumarizeChat', processLeadClient.connection.userId) | ||
const defaultChannel = processLeadClient.streamsClient.stream(cfg.announceChannelId) | ||
check(isDefined(defaultChannel), 'defaultChannel not found') | ||
// find the message in the default channel that contains the session id, this should already be there decrypted | ||
const message = defaultChannel.view.timeline.find( | ||
channelMessagePostWhere((value) => value.body.includes(cfg.sessionId)), | ||
) | ||
check(isDefined(message), 'message not found') | ||
|
||
await client.sendMessage( | ||
announceChannelId, | ||
`c${cfg.containerIndex}p${cfg.processIndex} Done freeMemory: ${getSystemInfo().FreeMemory}`, | ||
{ threadId: message.hashStr }, | ||
) | ||
const checkinCounts: Record<string, Record<string, number>> = {} | ||
|
||
// loop over clients and do summaries | ||
for (const client of localClients) { | ||
for (const channelId of cfg.channelIds) { | ||
// for each channel, count the number of joinChat checkins we got (look for sessionId) | ||
const messages = client.streamsClient.stream(channelId)?.view.timeline | ||
const checkInMesssages = | ||
messages?.filter( | ||
channelMessagePostWhere((value) => value.body.includes(cfg.sessionId)), | ||
) ?? [] | ||
|
||
const key = shortenHexString(channelId) | ||
checkinCounts[key] = { | ||
...checkinCounts[key], | ||
[checkInMesssages.length.toString()]: checkInMesssages.length, | ||
} | ||
} | ||
} | ||
|
||
const summary = { | ||
containerIndex: cfg.containerIndex, | ||
processIndex: cfg.processIndex, | ||
freeMemory: getSystemInfo().FreeMemory, | ||
checkinCounts, | ||
} | ||
|
||
await processLeadClient.sendMessage(cfg.announceChannelId, `Done ${makeCodeBlock(summary)}`, { | ||
threadId: message.hashStr, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
export function makeSillyMessage(opts?: { maxWords?: number }) { | ||
const maxWords = opts?.maxWords ?? 7 | ||
const w0 = [ | ||
'b', | ||
'd', | ||
'f', | ||
'g', | ||
'h', | ||
'j', | ||
'k', | ||
'l', | ||
'm', | ||
'n', | ||
'p', | ||
'r', | ||
's', | ||
't', | ||
'v', | ||
'w', | ||
'y', | ||
'z', | ||
'ch', | ||
'sh', | ||
'th', | ||
'zh', | ||
'ng', | ||
] | ||
const w1 = ['a', 'e', 'i', 'o', 'u', 'ə', 'ɑ', 'æ', 'ɛ', 'ɪ', 'i', 'ɔ', 'ʊ', 'u', 'ʌ'] | ||
const w2 = [ | ||
'ai', | ||
'au', | ||
'aw', | ||
'ay', | ||
'ea', | ||
'ee', | ||
'ei', | ||
'eu', | ||
'ew', | ||
'ey', | ||
'ie', | ||
'oa', | ||
'oi', | ||
'oo', | ||
'ou', | ||
'ow', | ||
'oy', | ||
'ar', | ||
'er', | ||
'ir', | ||
'or', | ||
'ur', | ||
] | ||
|
||
const wo = () => | ||
w0[Math.floor(Math.random() * w0.length)] + w1[Math.floor(Math.random() * w1.length)] | ||
|
||
const word = () => { | ||
const prefix = Array.from({ length: Math.floor(Math.random() * 3) + 1 }, wo).join('') | ||
const suffix = Math.random() > 0.8 ? w2[Math.floor(Math.random() * w2.length)] : '' | ||
return prefix + suffix | ||
} | ||
|
||
return Array.from({ length: Math.floor(Math.random() * (maxWords - 1)) + 1 }, word).join(' ') | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function makeCodeBlock(value: any): string { | ||
const str = JSON.stringify(value, null, 2) | ||
const ticks = '```' | ||
return `<br>\n ${ticks}\n${str}\n${ticks}\n` | ||
} |