-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
experimental/sdk/webpubsub-socketio-extension/examples/benchmark/README.md
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,13 @@ | ||
# Benchmark | ||
|
||
1. Run the server | ||
``` | ||
npm install | ||
node index.js <web-pubsub-connection-string> | ||
``` | ||
|
||
2. Open "https://socket-io-admin.scm.azurewebsites.net/wwwroot/#/benchmark" | ||
|
||
3. Fill in your endpoint in the form and connect. | ||
|
||
4. Fill test parameters then click "START BENCHMARK" |
48 changes: 48 additions & 0 deletions
48
experimental/sdk/webpubsub-socketio-extension/examples/benchmark/index.js
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,48 @@ | ||
const wpsExt = require("@azure/web-pubsub-socket.io") | ||
const express = require('express'); | ||
const app = express(); | ||
const http = require('http').Server(app); | ||
const io = require('socket.io') | ||
const { instrument } = require("@socket.io/admin-ui"); | ||
|
||
const wpsOptions = { | ||
hub: "eio_hub", | ||
connectionString: process.argv[2] || process.env.WebPubSubConnectionString, | ||
} | ||
|
||
const samplingInterval = 20; | ||
|
||
async function main() { | ||
const server = await io(http).useAzureSocketIO(wpsOptions) | ||
instrument(server, { auth: false, mode: "production", }); | ||
const benchmarkNs = server.of("/benchmark"); | ||
|
||
var lastReceivedIndex = 0; | ||
|
||
// Client -> Server time | ||
var min = 10000, max = 0, sum = 0; | ||
|
||
benchmarkNs.on('connection', (socket) => { | ||
socket.on('client to server event', (data) => { | ||
var index = data.split(",")[0]; | ||
var cost = new Date().getTime() - data.split(",")[1]; | ||
|
||
min = Math.min(min, cost); | ||
max = Math.max(max, cost); | ||
sum += cost; | ||
if (index % samplingInterval == 0) { | ||
console.log(`client -> Server (last=#${index}) | min: ${min} ms | max: ${max} ms | avg: ${sum / samplingInterval} ms`); | ||
min = 10000, max = 0, sum = 0; | ||
} | ||
socket.emit("server to client event", (data)); | ||
|
||
lastReceivedIndex = index; | ||
}); | ||
}); | ||
|
||
server.httpServer.listen(3000, () => { | ||
console.log('Visit http://localhost:%d', 3000); | ||
}); | ||
} | ||
|
||
main() |
16 changes: 16 additions & 0 deletions
16
experimental/sdk/webpubsub-socketio-extension/examples/benchmark/package.json
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,16 @@ | ||
{ | ||
"name": "webpubsub-for-socketio-benchmark", | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"private": true, | ||
"license": "BSD", | ||
"dependencies": { | ||
"@azure/web-pubsub-socket.io": "1.0.0-alpha.20230803.1", | ||
"@socket.io/admin-ui": "^0.5.1", | ||
"express": "~4.17.1", | ||
"socket.io": "^4.6.1" | ||
}, | ||
"scripts": { | ||
"start": "node index.js" | ||
} | ||
} |