Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Feb 1, 2024
1 parent 99a637a commit e30fb6f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 26 deletions.
19 changes: 12 additions & 7 deletions dev/tool/src/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,19 @@ export async function benchmark (
operations = 0
requestTime = 0
transfer = 0
for (const w of workspaceId) {
const r = extract(json.metrics as Metrics, w.name, 'client', 'handleRequest', 'process', 'find-all')
operations += r?.operations ?? 0
requestTime += (r?.value ?? 0) / (((r?.operations as number) ?? 0) + 1)
const r = extract(
json.metrics as Metrics,
'🧲 session',
'client',
'handleRequest',
'process',
'find-all'
)
operations += r?.operations ?? 0
requestTime += (r?.value ?? 0) / (((r?.operations as number) ?? 0) + 1)

const tr = extract(json.metrics as Metrics, w.name, 'client', 'handleRequest', '#send-data')
transfer += tr?.value ?? 0
}
const tr = extract(json.metrics as Metrics, '🧲 session', 'client', 'handleRequest', '#send-data')
transfer += tr?.value ?? 0
})
.catch((err) => {
console.log(err)
Expand Down
2 changes: 1 addition & 1 deletion pods/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function start (
}

const pipelineFactory: PipelineFactory = (ctx, workspace, upgrade, broadcast) => {
const wsMetrics = metrics.newChild('🧲 ' + workspace.workspaceName, {})
const wsMetrics = metrics.newChild('🧲 session', {})
const conf: DbConfiguration = {
domains: {
[DOMAIN_TX]: 'MongoTx',
Expand Down
6 changes: 4 additions & 2 deletions server/middleware/src/spaceSecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,16 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar

private async filterByDomain (domain: string, spaces: Ref<Space>[]): Promise<Ref<Space>[]> {
let domainSpaces = this.domainSpaces[domain]
if (domainSpaces === undefined) return []
if (domainSpaces instanceof Promise) {
domainSpaces = await domainSpaces
}
if (!(domainSpaces instanceof Set)) {
domainSpaces = await domainSpaces()
const p = domainSpaces()
this.domainSpaces[domain] = p
domainSpaces = await p
this.domainSpaces[domain] = domainSpaces
}
if (domainSpaces === undefined) return []
return spaces.filter((p) => (domainSpaces as Set<Ref<Space>>).has(p))
}

Expand Down
32 changes: 19 additions & 13 deletions server/ws/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ class TSessionManager implements SessionManager {
productId: string,
sessionId: string | undefined,
accountsUrl: string
): Promise<{ session: Session, context: MeasureContext } | { upgrade: true } | { error: any }> {
): Promise<
{ session: Session, context: MeasureContext, workspaceName: string } | { upgrade: true } | { error: any }
> {
return await baseCtx.with('📲 add-session', {}, async (ctx) => {
const wsString = toWorkspaceString(token.workspace, '@')

Expand All @@ -206,7 +208,7 @@ class TSessionManager implements SessionManager {
}
if (workspaceInfo === undefined) {
// No access to workspace for token.
return { error: new Error('No access to workspace for token.') }
return { error: new Error(`No access to workspace for token ${token.email} ${token.workspace.name}`) }
}

let workspace = this.workspaces.get(wsString)
Expand Down Expand Up @@ -264,7 +266,7 @@ class TSessionManager implements SessionManager {
session.useCompression
)
}
return { session, context: workspace.context }
return { session, context: workspace.context, workspaceName }
})
}

Expand All @@ -277,15 +279,16 @@ class TSessionManager implements SessionManager {
pipelineFactory: PipelineFactory,
ws: ConnectionSocket,
workspaceUrl: string,
name: string
workspaceName: string
): Promise<Pipeline> {
if (LOGGING_ENABLED) {
console.log(name, 'reloading workspace', JSON.stringify(token))
console.log(workspaceName, 'reloading workspace', JSON.stringify(token))
}
// If upgrade client is used.
// Drop all existing clients
await this.closeAll(wsString, workspace, 0, 'upgrade')
// Wipe workspace and update values.
workspace.workspaceName = workspaceName
if (!workspace.upgrade) {
// This is previous workspace, intended to be closed.
workspace.id = generateId()
Expand All @@ -295,7 +298,7 @@ class TSessionManager implements SessionManager {
// Re-create pipeline.
workspace.pipeline = pipelineFactory(
ctx,
{ ...token.workspace, workspaceUrl, workspaceName: name },
{ ...token.workspace, workspaceUrl, workspaceName },
true,
(tx, targets) => {
this.broadcastAll(workspace, tx, targets)
Expand Down Expand Up @@ -336,26 +339,27 @@ class TSessionManager implements SessionManager {
pipelineFactory: PipelineFactory,
token: Token,
workspaceUrl: string,
name: string
workspaceName: string
): Workspace {
const upgrade = token.extra?.model === 'upgrade'
const context = ctx.newChild('🧲 ' + name, {})
const context = ctx.newChild('🧲 session', {})
const workspace: Workspace = {
context,
id: generateId(),
pipeline: pipelineFactory(
context,
{ ...token.workspace, workspaceUrl, workspaceName: name },
{ ...token.workspace, workspaceUrl, workspaceName },
upgrade,
(tx, targets) => {
this.broadcastAll(workspace, tx, targets)
}
),
sessions: new Map(),
upgrade
upgrade,
workspaceName
}
if (LOGGING_ENABLED) console.time(name)
if (LOGGING_ENABLED) console.timeLog(name, 'Creating Workspace:', workspace.id)
if (LOGGING_ENABLED) console.time(workspaceName)
if (LOGGING_ENABLED) console.timeLog(workspaceName, 'Creating Workspace:', workspace.id)
this.workspaces.set(toWorkspaceString(token.workspace), workspace)
return workspace
}
Expand Down Expand Up @@ -569,7 +573,9 @@ class TSessionManager implements SessionManager {
msg: any,
workspace: string
): Promise<void> {
const userCtx = requestCtx.newChild('📞 client', {}) as SessionContext
const userCtx = requestCtx.newChild('📞 client', {
workspace: '🧲 ' + workspace
}) as SessionContext
userCtx.sessionId = service.sessionInstanceId ?? ''

// Calculate total number of clients
Expand Down
4 changes: 2 additions & 2 deletions server/ws/src/server_http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export function startHttpServer (
buff = Buffer.concat(msg).toString()
}
if (buff !== undefined) {
void handleRequest(session.context, session.session, cs, buff, token.workspace.name)
void handleRequest(session.context, session.session, cs, buff, session.workspaceName)
}
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
Expand All @@ -237,7 +237,7 @@ export function startHttpServer (
const b = buffer
buffer = undefined
for (const msg of b) {
await handleRequest(session.context, session.session, cs, msg, token.workspace.name)
await handleRequest(session.context, session.session, cs, msg, session.workspaceName)
}
}
wss.on('connection', handleConnection as any)
Expand Down
6 changes: 5 additions & 1 deletion server/ws/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export interface Workspace {
sessions: Map<string, { session: Session, socket: ConnectionSocket }>
upgrade: boolean
closing?: Promise<void>

workspaceName: string
}

/**
Expand All @@ -136,7 +138,9 @@ export interface SessionManager {
productId: string,
sessionId: string | undefined,
accountsUrl: string
) => Promise<{ session: Session, context: MeasureContext } | { upgrade: true } | { error: any }>
) => Promise<
{ session: Session, context: MeasureContext, workspaceName: string } | { upgrade: true } | { error: any }
>

broadcastAll: (workspace: Workspace, tx: Tx[], targets?: string[]) => void

Expand Down
1 change: 1 addition & 0 deletions tests/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ services:
- MINIO_SECRET_KEY=minioadmin
- REKONI_URL=http://rekoni:4005
- FRONT_URL=http://localhost:8083
- ACCOUNTS_URL=http://account:3000
collaborator:
image: hardcoreeng/collaborator
links:
Expand Down

0 comments on commit e30fb6f

Please sign in to comment.