-
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.
feat: handle reconnects in WS Transport, benchmarks (#8)
* async ws constructor, bump to 0.2.0 * benchmarks * add bench to ci * make reporter verbose * jk lol it doesnt report correctly * address id ! check * await promise * refactor ws transport check * use addEventListener variants of onxxx fns * remove extra todo * address review comments * refactor out event loop * update bench duration * run all * more comments, address nits * throw error instead * reuse reconnection promise * auto port allocation * make createWsTransports not async, basic test for reconnect logic * add even more tests
- Loading branch information
Showing
14 changed files
with
526 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import http from 'http'; | ||
import { bench, describe } from 'vitest'; | ||
import { | ||
createWebSocketServer, | ||
createWsTransports, | ||
onServerReady, | ||
waitForMessage, | ||
} from '../transport/util'; | ||
import largePayload from './largePayload.json'; | ||
import { TestServiceConstructor } from './integration.test'; | ||
import { createServer } from '../router/server'; | ||
import { createClient } from '../router/client'; | ||
import { StupidlyLargeService } from './typescript-stress.test'; | ||
|
||
let smallId = 0; | ||
let largeId = 0; | ||
const dummyPayloadSmall = () => ({ | ||
id: `${smallId++}`, | ||
from: 'client', | ||
to: 'SERVER', | ||
serviceName: 'test', | ||
procedureName: 'test', | ||
payload: { | ||
msg: 'cool', | ||
}, | ||
}); | ||
|
||
const dummyPayloadLarge = () => ({ | ||
id: `${largeId++}`, | ||
from: 'client', | ||
to: 'SERVER', | ||
serviceName: 'test', | ||
procedureName: 'test', | ||
payload: largePayload, | ||
}); | ||
|
||
const BENCH_DURATION = 1000; | ||
describe('transport level bandwidth', async () => { | ||
const server = http.createServer(); | ||
const port = await onServerReady(server); | ||
const webSocketServer = await createWebSocketServer(server); | ||
const [clientTransport, serverTransport] = createWsTransports( | ||
port, | ||
webSocketServer, | ||
); | ||
|
||
bench( | ||
'send and recv (small payload)', | ||
async () => { | ||
const id = clientTransport.send(dummyPayloadSmall()); | ||
await waitForMessage(serverTransport, (msg) => msg.id === id); | ||
return; | ||
}, | ||
{ time: BENCH_DURATION }, | ||
); | ||
|
||
bench( | ||
'send and recv (large payload)', | ||
async () => { | ||
const id = clientTransport.send(dummyPayloadLarge()); | ||
await waitForMessage(serverTransport, (msg) => msg.id === id); | ||
return; | ||
}, | ||
{ time: BENCH_DURATION }, | ||
); | ||
}); | ||
|
||
describe('simple router level bandwidth', async () => { | ||
const httpServer = http.createServer(); | ||
const port = await onServerReady(httpServer); | ||
const webSocketServer = await createWebSocketServer(httpServer); | ||
const [clientTransport, serverTransport] = createWsTransports( | ||
port, | ||
webSocketServer, | ||
); | ||
const serviceDefs = { test: TestServiceConstructor() }; | ||
const server = await createServer(serverTransport, serviceDefs); | ||
const client = createClient<typeof server>(clientTransport); | ||
|
||
bench( | ||
'rpc (wait for response)', | ||
async () => { | ||
await client.test.add({ n: 1 }); | ||
}, | ||
{ time: BENCH_DURATION }, | ||
); | ||
|
||
const [input, output] = await client.test.echo(); | ||
bench( | ||
'stream (wait for response)', | ||
async () => { | ||
input.push({ msg: 'abc', ignore: false }); | ||
await output.next(); | ||
}, | ||
{ time: BENCH_DURATION }, | ||
); | ||
|
||
bench( | ||
'stream', | ||
async () => { | ||
input.push({ msg: 'abc', ignore: false }); | ||
}, | ||
{ time: BENCH_DURATION }, | ||
); | ||
}); | ||
|
||
describe('complex (50 procedures) router level bandwidth', async () => { | ||
const httpServer = http.createServer(); | ||
const port = await onServerReady(httpServer); | ||
const webSocketServer = await createWebSocketServer(httpServer); | ||
const [clientTransport, serverTransport] = createWsTransports( | ||
port, | ||
webSocketServer, | ||
); | ||
const serviceDefs = { | ||
a: StupidlyLargeService(), | ||
b: StupidlyLargeService(), | ||
c: StupidlyLargeService(), | ||
d: StupidlyLargeService(), | ||
}; | ||
|
||
const server = await createServer(serverTransport, serviceDefs); | ||
const client = createClient<typeof server>(clientTransport); | ||
|
||
bench( | ||
'rpc (wait for response)', | ||
async () => { | ||
await client.b.f35({ a: 1 }); | ||
}, | ||
{ time: BENCH_DURATION }, | ||
); | ||
}); |
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,33 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"type": "articles", | ||
"id": "1", | ||
"attributes": { | ||
"title": "Example article", | ||
"body": "The shortest article. Ever.", | ||
"created": "2015-05-22T14:56:29.000Z", | ||
"updated": "2015-05-22T14:56:28.000Z" | ||
}, | ||
"relationships": { | ||
"author": { | ||
"data": { | ||
"id": "42", | ||
"type": "people" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"included": [ | ||
{ | ||
"type": "people", | ||
"id": "42", | ||
"attributes": { | ||
"name": "John", | ||
"age": 21, | ||
"gender": "male" | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.