首次提交

This commit is contained in:
2026-07-13 12:06:16 +08:00
commit e3c810b1a6
1690 changed files with 228324 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
#! /usr/bin/env node
const mqtt = require('mqtt')
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, keepalive: 0 })
const interval = 5000
let sent = 0
function count () {
console.log('sent/s', sent / interval * 1000)
sent = 0
}
setInterval(count, interval)
function immediatePublish () {
setImmediate(publish)
}
function publish () {
sent++
client.publish('test', 'payload', immediatePublish)
}
client.on('connect', publish)
client.on('offline', function () {
console.log('offline')
})
client.on('error', function () {
console.log('reconnect!')
client.stream.end()
})
+36
View File
@@ -0,0 +1,36 @@
#! /usr/bin/env node
const mqtt = require('mqtt')
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, keepalive: 0 })
const interval = 5000
let sent = 0
function count () {
console.log('sent/s', sent / interval * 1000)
sent = 0
}
setInterval(count, interval)
function publish () {
sent++
client.publish('test', 'payload', { qos: 1 }, publish)
}
client.setMaxListeners(100)
client.on('connect', function () {
for (let i = 0; i < 50; i++) {
publish()
}
})
client.on('offline', function () {
console.log('offline')
})
client.on('error', function () {
console.log('reconnect!')
client.stream.end()
})
+53
View File
@@ -0,0 +1,53 @@
#! /usr/bin/env node
const mqtt = require('mqtt')
const convertHrtime = require('convert-hrtime')
const mode = require('compute-mode')
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, keepalive: 0 })
const interval = 5000
let sent = 0
const latencies = []
function count () {
console.log('sent/s', sent / interval * 1000)
sent = 0
}
setInterval(count, interval)
function publish () {
sent++
client.publish('test', JSON.stringify(process.hrtime()), { qos: 1 })
}
function subscribe () {
client.subscribe('test', { qos: 1 }, publish)
}
client.on('connect', subscribe)
client.on('message', publish)
client.on('message', function (topic, payload) {
const sentAt = JSON.parse(payload)
const diff = process.hrtime(sentAt)
latencies.push(convertHrtime(diff).ms)
})
client.on('offline', function () {
console.log('offline')
})
client.on('error', function () {
console.log('reconnect!')
client.stream.end()
})
process.on('SIGINT', function () {
const total = latencies.reduce(function (acc, num) {
return acc + num
})
console.log('total', total)
console.log('average', total / latencies.length)
console.log('mode', mode(latencies))
process.exit(0)
})
+25
View File
@@ -0,0 +1,25 @@
'use strict'
// To be used with cpuprofilify http://npm.im/cpuprofilify
const aedes = require('../')()
const server = require('net').createServer(aedes.handle)
const port = 1883
server.listen(port, function () {
console.error('server listening on port', port, 'pid', process.pid)
})
aedes.on('clientError', function (client, err) {
console.error('client error', client.id, err.message)
})
// Cleanly shut down process on SIGTERM to ensure that perf-<pid>.map gets flushed
process.on('SIGINT', onSIGINT)
function onSIGINT () {
// IMPORTANT to log on stderr, to not clutter stdout which is purely for data, i.e. dtrace stacks
console.error('Caught SIGTERM, shutting down.')
server.close()
process.exit(0)
}
+23
View File
@@ -0,0 +1,23 @@
#! /usr/bin/env node
const mqtt = require('mqtt')
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, encoding: 'binary', keepalive: 0 })
const interval = 5000
let counter = 0
function count () {
console.log('received/s', counter / interval * 1000)
counter = 0
}
setInterval(count, interval)
client.on('connect', function () {
count()
this.subscribe('test')
this.on('message', function () {
counter++
})
})
+33
View File
@@ -0,0 +1,33 @@
#! /usr/bin/env node
const mqtt = require('mqtt')
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, encoding: 'binary', keepalive: 0 })
const interval = 5000
let counter = 0
function count () {
console.log('received/s', counter / interval * 1000)
counter = 0
}
setInterval(count, interval)
client.on('connect', function () {
this.subscribe('test', { qos: 1 })
})
client.handleMessage = function (packet, done) {
counter++
done()
}
client.on('offline', function () {
console.log('offline')
})
client.on('error', function () {
console.log('reconnect!')
client.stream.end()
})