Snapshot of verae-nats-cluster (optimal NATS config study)
This commit is contained in:
commit
8639ca27ee
184 changed files with 10626 additions and 0 deletions
33
scripts/mqtt-probe.mjs
Executable file
33
scripts/mqtt-probe.mjs
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env node
|
||||
/** MQTT QoS0 publish rate against nats-server MQTT gateway. */
|
||||
import mqtt from "mqtt";
|
||||
|
||||
const url = process.argv[2] || "mqtt://10.10.10.21:1883";
|
||||
const count = Number(process.argv[3] || 5000);
|
||||
const size = Number(process.argv[4] || 128);
|
||||
const payload = Buffer.alloc(size, 9);
|
||||
const topic = `bench/mqtt/${process.pid}`;
|
||||
|
||||
const c = mqtt.connect(url, { reconnectPeriod: 0, connectTimeout: 5000 });
|
||||
await new Promise((res, rej) => {
|
||||
c.on("connect", res);
|
||||
c.on("error", rej);
|
||||
});
|
||||
const t0 = process.hrtime.bigint();
|
||||
for (let i = 0; i < count; i++) {
|
||||
await new Promise((res, rej) => c.publish(topic, payload, { qos: 0 }, (err) => (err ? rej(err) : res())));
|
||||
}
|
||||
const ns = Number(process.hrtime.bigint() - t0);
|
||||
c.end(true);
|
||||
const sec = ns / 1e9;
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
mode: "mqtt-qos0",
|
||||
count,
|
||||
size,
|
||||
url,
|
||||
secs: Number(sec.toFixed(3)),
|
||||
pubs_per_sec: Math.round(count / sec),
|
||||
mb_per_sec: Number(((count * size) / sec / 1e6).toFixed(2)),
|
||||
}),
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue