The repo contains example code for doing comparison performance tests between HTTP and MQTT against Google Cloud IoT Core. The test simulates a virtual device that sends telemetry events to Google Cloud IoT Core. The locust.io framework is utilized to perform the tests as well as gathering and presenting the test results.
The httpClient.py adapt the HttpLocust by adding the JWT in request headers, which is needed to authenticate against the Cloud IoT Core - HTTP Bridge. The telemetry events is delivered to Cloud IoT Core by calling the publishEvent endpoint with payload data.
For the MQTT part of the test, a custom locust client is implemented using the paho mqtt python client to properly interact with Cloud IoT Core - MQTT Bridge. The client handles connect and disconnect to MQTT server and is capable of sending multiple events. The time it take to conduct each of the steps are measured and send to locust.io by triggering the request_success
and request_failure
events.
For event publishing through HTTP the request and response time is measured for each event.
For the MQTT case because of the protocol is publish/subscribe oriented there is a connection establishing process between the client and the server before event could be published. So we choose to measure the connect and disconnect time together with the event publishing time, as the total time it takes to publish event. We also choose to send the events with QoS 1 which guarantees at least once delivery through a PUBACK
response which matches the HTTP request and response cycle.
With a established MQTT connection multiple events could be send, we choose to measure the time it takes to send 1, 10, 100 and 1000 events between one connect/disconnect cycle.
We assume you already have a GCP project setup with an IoT Core registry created, and inside of registry there's a device created with a public/private key pair stored in you local environment.
Follow the Getting Started and Creating Registries and Devices to create this prerequisite cloud environment.
Following steps are all done on your local environment where the tests will be conducted.
- Git
- Python 2.7
Clone the repoistory:
git clone https://github.com/kingman/load-test-iot-core.git
cd load-test-iot-core
curl https://pki.google.com/roots.pem > roots.pem
cp set_env_template set_env.sh
Put in the proper values for you setup by editing then set_env.sh
file and set the variables
source set_env.sh
virtualenv env && source env/bin/activate
pip install -r requirements.txt
Start locust with the MQTT client
locust --no-reset-stats -f mqttClient.py
Open the web interface at http://127.0.0.1:8089/ and choose the number of simulated user and ramp up pace to execute the test.
Start locust with the HTTP client
locust --host='https://cloudiotdevice.googleapis.com/v1' -f httpClient.py
Open the web interface at http://127.0.0.1:8089/ and choose the number of simulated user and ramp up pace to execute the test.