throughputCounter.js 451 B

1234567891011121314151617181920212223
  1. #! /usr/bin/env node
  2. const mqtt = require('mqtt')
  3. const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, encoding: 'binary', keepalive: 0 })
  4. const interval = 5000
  5. let counter = 0
  6. function count () {
  7. console.log('received/s', counter / interval * 1000)
  8. counter = 0
  9. }
  10. setInterval(count, interval)
  11. client.on('connect', function () {
  12. count()
  13. this.subscribe('test')
  14. this.on('message', function () {
  15. counter++
  16. })
  17. })