Skip to content

Commit

Permalink
Add better summaries to the stress tests (#23)
Browse files Browse the repository at this point in the history
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
texuf authored May 21, 2024
1 parent 02474ff commit 8067dbf
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 103 deletions.
1 change: 1 addition & 0 deletions core/stress/scripts/localhost_chat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ echo "stress/scripts/localhost_chat.sh"

export SPACE_ID="${SPACE_ID}"
export CHANNEL_IDS="${CHANNEL_IDS}"
export ANNOUNCE_CHANNEL_ID="${ANNOUNCE_CHANNEL_ID:-}"

export RIVER_ENV="${RIVER_ENV:-local_single}"
export STRESS_MODE="${STRESS_MODE:-chat}"
Expand Down
65 changes: 1 addition & 64 deletions core/stress/src/mode/chat/chitChat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { dlogger } from '@river-build/dlog'
import { StressClient } from '../../utils/stressClient'
import { ChatConfig } from './types'
import { makeSillyMessage } from '../../utils/messages'

export async function chitChat(client: StressClient, cfg: ChatConfig) {
const logger = dlogger(`stress:chitchat:${client.logId}`)
Expand All @@ -16,67 +17,3 @@ export async function chitChat(client: StressClient, cfg: ChatConfig) {
await new Promise((resolve) => setTimeout(resolve, Math.random() * averateWaitTime))
}
}
function makeSillyMessage() {
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)]
// range over 0...Math.floor(Math.random()*3) and add a random wo

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() * 7) + 1 }, word).join(' ')
}
8 changes: 5 additions & 3 deletions core/stress/src/mode/chat/joinChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { dlogger } from '@river-build/dlog'
import { getRandomEmoji } from '../../utils/emoji'
import { getSystemInfo } from '../../utils/systemInfo'
import { channelMessagePostWhere } from '../../utils/timeline'
import { makeSillyMessage } from '../../utils/messages'

export async function joinChat(client: StressClient, cfg: ChatConfig) {
const logger = dlogger(`stress:joinChat:${client.logId}}`)
Expand Down Expand Up @@ -71,10 +72,11 @@ export async function joinChat(client: StressClient, cfg: ChatConfig) {
) {
await client.streamsClient.joinStream(channelId)
await client.streamsClient.waitForStream(channelId)
await client.sendMessage(channelId, `I'm in! ${cfg.sessionId}`)
} else {
await client.sendMessage(channelId, `Let's go! ${cfg.sessionId}`)
}
await client.sendMessage(
channelId,
`${makeSillyMessage({ maxWords: 2 })}! ${cfg.sessionId}`,
)
}

logger.log('done')
Expand Down
24 changes: 10 additions & 14 deletions core/stress/src/mode/chat/kickoffChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getSystemInfo } from '../../utils/systemInfo'
import { BigNumber } from 'ethers'
import { ChatConfig } from './types'
import { check, dlogger } from '@river-build/dlog'
import { makeCodeBlock } from '../../utils/messages'

const logger = dlogger('stress:kickoffChat')

Expand Down Expand Up @@ -30,24 +31,19 @@ export async function kickoffChat(rootClient: StressClient, cfg: ChatConfig) {
`hello, we're starting the stress test now!, containers: ${cfg.containerCount} ppc: ${cfg.processesPerContainer} clients: ${cfg.clientsCount} sessionId: ${sessionId}`,
)

const initialStats = JSON.stringify(
{
timeToShareKeys: shareKeysDuration + 'ms',
walletBalance: balance.toString(),
testDuration: cfg.duration,
clientsCount: cfg.clientsCount,
},
null,
2,
)

const systemInfo = JSON.stringify(getSystemInfo(), null, 2)
const ticks = '```'
const initialStats = {
timeToShareKeys: shareKeysDuration + 'ms',
walletBalance: balance.toString(),
testDuration: cfg.duration,
clientsCount: cfg.clientsCount,
}

logger.log('start thread')
await rootClient.sendMessage(
announceChannelId,
`System Info:<br>\n ${ticks}\n ${systemInfo}\n ${ticks}\n Initial Stats:<br>\n ${ticks}\n ${initialStats}\n ${ticks}\n`,
`System Info: ${makeCodeBlock(getSystemInfo())} Initial Stats: ${makeCodeBlock(
initialStats,
)}`,
{ threadId: eventId },
)

Expand Down
60 changes: 42 additions & 18 deletions core/stress/src/mode/chat/sumarizeChat.ts
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,
})
}
9 changes: 5 additions & 4 deletions core/stress/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ function getChatConfig(): ChatConfig {
const clientEndIndex = clientStartIndex + clientsPerProcess
const spaceId = process.env.SPACE_ID
const channelIds = process.env.CHANNEL_IDS.split(',')
const announceChannelId = process.env.ANNOUNCE_CHANNEL_ID
? process.env.ANNOUNCE_CHANNEL_ID
: makeDefaultChannelStreamId(spaceId)
const announceChannelId =
process.env.ANNOUNCE_CHANNEL_ID && process.env.ANNOUNCE_CHANNEL_ID.length > 0
? process.env.ANNOUNCE_CHANNEL_ID
: makeDefaultChannelStreamId(spaceId)
const allWallets = generateWalletsFromSeed(getRootWallet().mnemonic, 0, clientsCount)
const wallets = allWallets.slice(clientStartIndex, clientEndIndex)
if (clientStartIndex >= clientEndIndex) {
Expand Down Expand Up @@ -140,7 +141,7 @@ async function startStressChat() {
await Promise.all(clients.map((client) => chitChat(client, chatConfig)))

logger.log('sumarizeChat')
await sumarizeChat(clients[0], chatConfig)
await sumarizeChat(clients, chatConfig)

logger.log('done')
}
Expand Down
71 changes: 71 additions & 0 deletions core/stress/src/utils/messages.ts
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`
}

0 comments on commit 8067dbf

Please sign in to comment.