Skip to content

Instantly share code, notes, and snippets.

@stephendeyoung
Created March 9, 2018 09:03
Show Gist options
  • Save stephendeyoung/3180ce2ec527332e0ece6eee573e6ecb to your computer and use it in GitHub Desktop.
Save stephendeyoung/3180ce2ec527332e0ece6eee573e6ecb to your computer and use it in GitHub Desktop.
const mqtt = require('mqtt');
const _ = require('lodash');
const memwatch = require('memwatch-next');
const util = require('util');
const setTimeoutPromise = util.promisify(setTimeout);
memwatch.on('leak', (info) => {
console.error('Memory leak detected:\n', info);
});
const NUMBER_OF_CLIENTS = parseInt(process.env.NUMBER_OF_CLIENTS, 10) || 5;
console.log('NUMBER_OF_CLIENTS: ', NUMBER_OF_CLIENTS)
_.times(NUMBER_OF_CLIENTS, async (n) => {
await setTimeoutPromise(n * 500);
console.log('connecting client')
const client = mqtt.connect('mqtt://broker.hivemq.com');
client.subscribe(`/blah`, err => {
if (err) {
console.error(err, 'Subscription error')
}
})
client.on('error', err => {
console.error(err, 'Error with mqtt client');
})
client.once('connect', () => {
console.log(`client connected`)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment