Load Testing a REST API on a Low-Power IoT Platform
Web-based APIs have exploded in use from banking, eCommerce, medical devices, entertainment and more. From Facebook to Amazon, APIs are being used basically everywhere on the web today.
One arena where web APIs are especially useful is the Internet of Things. These devices are often low-power network connected (wifi or ethernet) with minimal CPU capabilities.
We often test web APIs that run in highly scalable cloud environments where most customers will deploy their applications. When running on a low-power, limited platform, the efficiency of the API becomes much more important.
We decided to run this series of tests on the very popular Raspberry Pi platform running a python-based API. The API being tested is the Webiopi, which provides an HTTP and REST API interface to a wide variety of sensors and GPIO on the platform. Think of it as a web-based window into the physical world of automation and sensors.
Why anyone would load test such a low-power device?
The principals for testing APIs apply quite well to this test scenario. Being constrained on CPU resources forces developers to be efficient in their coding and API development, which is something that’s important regardless of the platform.
This particular Raspberry Pi used in “production” at my home monitors a GPIO input for a rising edge, indicating an event has taken place. The event in question is a doorbell press, which triggers a current sensor that outputs a “1” when current is flowing.
When this event occurs a python script pulls the most recent still image from a security camera, packages it in an email and sends it to me. Because this is event-driven, requires no monitoring and doesn’t bother me with constant alerts, it is extremely useful.
It’s also very popular with visitors who know how the system works.
A note on the architecture: This testing was done directly from our cloud-based platform directly to the Raspberry Pi device (via port forwarding on my firewall). This is fine for temporary testing but not the most secure or scalable solution for production use.
In a future article we will explore some additional options to expose this functionality to the web, including Weaved, a new cloud-based service that securely and rapidly deploys IoT capabilities. Weaved has a direct integration to Webiopi that provides secure access to the API and web front end without port forwarding.
The API being tested is a REST API with an HTTP front end. REST APIs are very popular and can be a very efficient means of checking and updating different types of data.
The first test I ran was a very simple script that gets the status of GPIO #10 using the following HTTP string: http://petermcannell.com:82/GPIO/10/value
The user scenario (script) is very simple for this initial test and can easily be edited to test other functions:
... to read more articles, visit http://sqa.fyicenter.com/art/