S
S
serious9112016-05-23 13:41:10
JavaScript
serious911, 2016-05-23 13:41:10

Load testing Socket.IO / SockJS?

Hello.
Can you please tell me how to test NodeJS + Websockets (Socket.IO/SockJS)?
On a small Ubuntu 14.04 LTS server, NodeJS 4.4.4 is installed and 2 applications are running on port 8081 on Express + Socket.IO and SockJS. It is necessary to check that everything is working fine + check how the application will behave under load (at least 100 simultaneous connections). At this stage, the application is very simple like Hello World, but things will gradually get more complicated. The client simply connects to the socket and prints all messages to the console.
server.js (SockJS) code:

var http = require('http');
    var sockjs = require('sockjs');

    var echo = sockjs.createServer({ sockjs_url: 'http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js' });
    echo.on('connection', function(socket) {
        socket.write('connected');
        socket.write('Hello world');

        socket.on('close', function() {
            socket.write('disconnected');
        });
    });

    var server = http.createServer();
    echo.installHandlers(server, {prefix:'/websocket'});

    server.listen(8081, '0.0.0.0');

server.js code (Socket.io+ Express):
var express = require('express')();
    var http = require('http').Server(express);
    var io = require('socket.io')(http, {path: '/websocket'});

    io.on('connection', function (socket) {
        io.emit('message', 'connected');
        io.emit('message', 'Hello world');
    });

    express.get('/index.html', function (req, res) {
        res.sendFile(__dirname + '/index.html');
    });

    express.get('/socket.io.js', function (req, res) {
        res.sendFile(__dirname + '/socket.io.js');
    });

    http.listen(8081, '0.0.0.0');

We need a very simple (preferably console) and workable utility for Ubuntu / MacOS, which can generate connections to websockets. Tried using wsbench , thor , odin-ws , and a few other utilities from GitHub but couldn't verify anything. Basically either does not start after installation or displays errors.
node wsbench -c 100 -r 10 ws://******de.net:8081/websocket

/home/n****t/wsbench/lib/optparse.js:144
while(l--> 0) if(LONG_SWITCH_RE(arr[l])) return true;
^
TypeError: object is not a function
at contains_expr (/home/nan***1t/wsbench/lib/optparse.js:144:23)
at build_rules (/home/n**m1t/wsbench/lib/optparse.js :77:13)
at Object.OptionParser.parse(/home/nan**t/wsbench/lib/optparse.js:224:21)
at Object. (/home/n*****t/wsbench/wsbench:113:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10 )
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)

thor --amount 1 ws://******de.net:8081/websocket

Connecting to ws://******.net:8081/websocket
Online 618 milliseconds
Time taken 618 milliseconds
Connected 0
Disconnected 0
Failed 1
Total transferred 0B
Total received 0B
Durations (ms): min mean stddev median max
Handshaking NaN NaN NaN NaN NaN
Latency NaN NaN NaN NaN NaN
Percentile (ms): 50% 66% 75% 80% 90% 95% 98% 98% 100%
Handshaking NaN NaN NaN NaN NaN NaN NaN NaN NaN
Latency NaN NaN NaN NaN NaN NaN NaN NaN NaN
Received errors:
1x socket hang up

It will connect through the browser to the websocket and see Hello World, it turned out, but it is not possible to test.
Please share working examples/utilities/links for testing Socket.io/SockJS.
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Aksentiev, 2016-05-23
@Sanasol

https://gist.github.com/S-anasol/3eaf154e2beb5ca1c...
Here is an example for socket.io
1. Install the required websocket client for nodejs
2. Write a script that makes the required number of connections
3. ...
4. Profit

D
Danil Biryukov-Romanov, 2016-05-23
@urtow

https://github.com/observing/thor
Here is a ready tool for loading Websocket. I think to fasten it to Socketio is not a problem.

S
sawa4, 2016-12-07
@sawa4

Installed on ubuntu socket io in Laravel project.
How to find out what port the socket server is running on? default like 80
But application throws GET laravel/socket.io 404 Not Found

D
Daniil Chepenko, 2015-08-12
@zkid

Yes. there is a kind of application that combines Habr, Geek and Megamind

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question