Petr Shypila Petr Shypila - 1 year ago 79
Javascript Question

How to open a pool of websocket connections

I need to perform a load testing on our websocket service.
Is there a way how can I open a bunch of websocket connections from a single workstation?

I already tried npm's

modules to launch them with NodeJS. It works fine with a single connection, but when I try to open them in a for-loop it throws an exception or uses only last open client.

Answer Source

If you want to do it from a single workstation, you can use child processes :

app.js :

var cp = require('child_process');
var children = [];
var max = 10; // tweak this to whatever you want
for(var i = 0; i<max; i++){
    children[i] = cp.fork('./child.js');
    .on('error', function(e) {
    }).on('exit', function(code) {
      console.log('exit with code',code);

then in child.js, just have a script that starts a connection. you can also send messages between parent and child, using the child process API

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download