Reputation: 1509
I need to perform a load testing on our websocket service. Is there a way to open multiple websocket connections from a single workstation?
I already tried npm ws
and websocket
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.
Upvotes: 0
Views: 1534
Reputation: 12409
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) {
console.log(e);
}).on('message',function(m){
console.log(m)
}).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
Upvotes: 2