How to use k6 to perform mqtt load testing?


I would like to use k6 to perform MQTT load testing, I tried to use mqttjs by using the k6-es6 starter but I’m not able to get a bundled test that is working.

import url from 'url';           // I had to add that to avoid ReferenceError: URL is not defined
import mqtt from 'mqtt';

export default function() {
  const client = mqtt.connect('mqtt://localhost:1883');

The last error I got : “Invalid regular expression (re2):”

Is there any people that already got success with k§ and mqtt?


You currently can’t do MQTT load testing with k6. Since it involves making network connections, you wouldn’t be able to browserify or webpack a node.js module to do the job, it needs to be done as a k6 module or plugin.

You can follow Support for MQTT protocol · Issue #1269 · grafana/k6 · GitHub for updates on when such functionality will be available natively in k6, though it’s very likely it will first ship as a separate plugin via the new xk6 system (, GitHub - grafana/xk6: Build k6 with extensions)

1 Like