forked from moscajs/aedes-persistence-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.js
38 lines (35 loc) · 901 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
// npm install mqtt fastq
// command to run : node fastbench 25000
const queue = require('fastq')(worker, 1)
const mqtt = require('mqtt')
let connected = 1
const clients = []
let count = 0
let subscriptions = 0
const st = Date.now()
console.log('Started connecting clients', st)
setInterval(() => {
console.log(`${Date.now()}-${count} - ${subscriptions}`)
}, 1000)
function worker (arg, cb) {
clients[count] = mqtt.connect({
port: 1883,
keepalive: 60
})
clients[count].on('connect', (clientObj => {
return () => {
connected++
if (connected === process.argv[2]) {
console.log('done connecting clients', Date.now() - st)
}
clientObj.subscribe(clientObj.options.clientId, () => {
subscriptions++
})
cb(null, 42 * 2)
}
})(clients[count]))
count++
}
for (let i = 0; i < process.argv[2]; i++) {
queue.push(42, () => {})
}