Created
March 1, 2013 15:13
-
-
Save Siedrix/5065277 to your computer and use it in GitHub Desktop.
Socket io stress test. Needs more work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install | |
node server.js | |
node swarm [usersSpawnPerSecond] [MessagesSendPerUserPerSecond] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var io = require('socket.io').listen(8080, { | |
"log level" : 0 | |
}); | |
var connectedUsersCount = 0; | |
var messagesPerSecond = 0; | |
io.sockets.on('connection', function(socket) { | |
connectedUsersCount++; | |
socket.on('chat', function(data) { | |
// logger.info("chat message arrived"); | |
socket.broadcast.emit('chat', {text:data.text}); | |
messagesPerSecond++; | |
}); | |
socket.on('disconnect', function(data) { | |
connectedUsersCount--; | |
}); | |
}); | |
setTimeout(logStatus, 1000); | |
function logStatus() { | |
setTimeout(logStatus, 1000); | |
console.log("users: " + connectedUsersCount + "\tmessagesPerSecond: " + messagesPerSecond); | |
messagesPerSecond = 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var spawn = require('child_process').spawn, | |
_ = require('underscore'); | |
var dronesSpawnPerSecond = process.argv[2]; | |
var messagePerSecond = process.argv[3]; | |
var drones = []; | |
setInterval(function(){ | |
var drone = spawn('node', ['./test.js', messagePerSecond]); | |
drones.push(drone); | |
console.log('drones spawn', drones.length); | |
}, 1000 / dronesSpawnPerSecond); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var io = require('socket.io-client'); | |
var socket = io.connect('ws://localhost:8080'); | |
var sendMessagePerSecond = process.argv[2] | |
//var socket = io.connect('http://localhost:8001/live'); | |
console.log(process.argv[2]) | |
var messagesPerSecond = 0, | |
i = 0; | |
socket.emit('chat', { my: 'data' }); | |
socket.on('chat', function(){ | |
messagesPerSecond++; | |
}); | |
setInterval(function(){ | |
socket.emit('chat', { content: 'lolz' + Math.random() }); | |
}, 1000 / sendMessagePerSecond); | |
setTimeout(logStatus, 1000); | |
function logStatus() { | |
setTimeout(logStatus, 1000); | |
console.log("messagesPerSecond: " + messagesPerSecond); | |
console.log("Connected: ", socket.socket.connected); | |
messagesPerSecond = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment