A very simple MQTT load generator tool written in Go. The tool will first establish all the connections to the target broker and only then start the publishing of messages.
A simple checker that counts received messages is also provided.
- Go 1.19.1+ (probably works with older versions too!)
./build_all.sh
will generate the binariescmd/load_generator/mqtt-load-generator
cmd/checker/checker
./cmd/load_generator/mqtt-load-generator --help
will show all the supported options for the load generator./cmd/checker/checker --help
will show all the supported options for the checker
Example to publish 1000 messages with 1KB payload size with a 1 ms wait between messages using 100 concurrent clients
./cmd/load_generator/mqtt-load-generator -c 1000 -s 1000 -t /golang/pub -i 1 -n 100 -u secret -P mega_secret -h localhost -p 1883
To count incoming messages you can use the checker
./cmd/checker/checker -h localhost -p 1883 -u secret -P ultra_secret -t /golang/pub
To check all the available options run
./cmd/load_generator/mqtt-load-generator --help
To create a docker image for the load generator:
docker build -t mqtt-load-generator .
To run a docker container from it reuse the same command line like above with:
docker run --rm -it mqtt-load-generator -c 1000 -s 1000 -t /golang/pub -i 1 -n 100 -u secret -P mega_secret -h localhost -p 1883
docker run --entrypoint /checker --rm -it mqtt-load-generator -t /golang/pub -u secret -P mega_secret -h localhost -p 1883
Here are a few methods of running the image in a Kubernetes cluster (e.g., to creating the load nearer to cluster resources by using cluster-local addresses):
kubectl run mqtt-load-generator --image=ghcr.io/pablitovicente/mqtt-load-generator:v1.0.7 \
-- -h <mqtt-broker-address> -p 1883 -u secret -P mega_secret \
-c 1000 -s 1000 -t /golang/pub -i 1 -n 100
kubectl run mqtt-load-checker --image=ghcr.io/pablitovicente/mqtt-load-generator:v1.0.7 --command \
-- /checker -h <mqtt-broker-address> -p 1883 -u secret -P mega_secret \
-t /golang/pub --disable-bar
To run as a Kubernetes job you can adjust the file k8s/job.yaml
and apply it with:
kubectl create -f k8s/job.yaml
To view the log output use:
kubectl logs -f -l job-name=mqtt-load-generator
To restart when one run is finished you can use:
kubectl delete jobs.batch -l app=mqtt-load-generator ; kubectl create -f k8s/job.yaml
Run multiple jobs parallel
To run multiple jobs in parallel you adjust parameter spec.parallelism
in k8s/job.yaml
Delete multiple jobs
To clean up all mqtt-load-generator jobs you can run:
kubectl delete jobs.batch -l app=mqtt-load-generator
kubectl create -f k8s/checker-deployment.yaml
- Use more idiomatic Go style
Support TLSAddedSupport mTlSAdded- Improve error handling
- Add tests (this should be first :P)