Skip to content

Commit

Permalink
[benchmark] Add Unix domain sockets to bench (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianhopebailie authored and lpinca committed Oct 11, 2018
1 parent 9022a0d commit d2317b1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions bench/speed.js
@@ -1,24 +1,33 @@
'use strict';

const cluster = require('cluster');
const http = require('http');

const WebSocket = require('..');

const port = 8181;
const path = '';
// const path = '/tmp/wss.sock';

if (cluster.isMaster) {
const server = http.createServer();
const wss = new WebSocket.Server({
maxPayload: 600 * 1024 * 1024,
perMessageDeflate: false,
clientTracking: false,
port
}, () => cluster.fork());
server
});

wss.on('connection', (ws) => {
ws.on('message', (data) => ws.send(data));
});

cluster.on('exit', () => wss.close());
server.listen(path ? { path } : { port }, () => cluster.fork());

cluster.on('exit', () => {
wss.close();
server.close();
});
} else {
const configs = [
[true, 10000, 64],
Expand Down Expand Up @@ -52,9 +61,12 @@ if (cluster.isMaster) {
randomBytes[i] = ~~(Math.random() * 127);
}

console.log(`Testing ws on ${path || '[::]:' + port}`);

const runConfig = (useBinary, roundtrips, size, cb) => {
const data = randomBytes.slice(0, size);
const ws = new WebSocket(`ws://localhost:${port}`, {
const url = path ? `ws+unix://${path}` : `ws://localhost:${port}`;
const ws = new WebSocket(url, {
maxPayload: 600 * 1024 * 1024
});
var roundtrip = 0;
Expand Down

0 comments on commit d2317b1

Please sign in to comment.