forked from moscajs/aedes-persistence-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.js
42 lines (38 loc) · 973 Bytes
/
tester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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 subscriptions = 0
var st = Date.now()
console.log('Started connecting clients', st)
setInterval(function () {
console.log(new Date() + '-' + count + ' - ' + subscriptions)
}, 1000)
function worker (arg, cb) {
clients[count] = mqtt.connect({
port: 1883,
keepalive: 60
})
clients[count].on('connect',
(function (clientObj) {
return function () {
connected++
if (connected === process.argv[2]) {
console.log('done connecting clients', Date.now() - st)
}
clientObj.subscribe(clientObj.options.clientId, function () {
subscriptions++
})
cb(null, 42 * 2)
}
}(clients[count]))
)
count++
}
for (var i = 0; i < process.argv[2]; i++) {
queue.push(42, function () {})
}