Skip to content

Commit

Permalink
add benchmark tool
Browse files Browse the repository at this point in the history
  • Loading branch information
xingsy97 committed Aug 4, 2023
1 parent 8562760 commit c0629a6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
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"
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()
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"
}
}

0 comments on commit c0629a6

Please sign in to comment.