Created
January 16, 2017 06:24
-
-
Save GavinDmello/dda612661df4db11ba84b41097470c95 to your computer and use it in GitHub Desktop.
bench connections using fastq
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 mqtt fastq | |
// command to run : node fastbench 25000 | |
'use strict' | |
var queue = require('fastq')(worker, 1) | |
var mqtt = require('mqtt') | |
var connected = 1 | |
var clients = [] | |
var count = 0 | |
var st = Date.now() | |
console.log('Started connecting clients', st) | |
function worker (arg, cb) { | |
clients[count] = mqtt.connect({ | |
host: "127.0.0.1", | |
port : 1883, | |
keepalive : 60 | |
}) | |
clients[count].on('connect', function con () { | |
connected++ | |
if (connected == process.argv[2]) { | |
console.log('done connecting clients', Date.now() - st) | |
} | |
cb(null, 42*2) | |
}) | |
count++ | |
} | |
for (var i = 0; i < process.argv[2]; i++) { | |
queue.push(42, function() {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment