Last active
January 10, 2017 11:01
-
-
Save GavinDmello/4636114be7f11f36a9778c186470108a to your computer and use it in GitHub Desktop.
Bench connections in mqtt
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
/* | |
run file with command node bench 10000 | |
where 10000 is the number of clients you want to connect | |
*/ | |
'use strict' | |
var queue = require('fastq')(worker, 10) | |
var mqtt = require('mqtt') | |
var connected = 1 | |
var clients = [] | |
var count = 0 | |
var st = Date.now() | |
function worker (arg, cb) { | |
clients[count] = mqtt.connect({ | |
host: "127.0.0.1", | |
port : 1886 | |
}) | |
clients[count].on('connect', con) | |
count++ | |
cb(null, 42 * 2) | |
} | |
for (var i = 0; i < process.argv[2]; i++) { | |
queue.push(42, function() {}) | |
} | |
function con () { | |
connected++ | |
if (connected == process.argv[2]) { | |
console.log('done', Date.now() - st) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment