Hi @rberkelm !
Looking at the thread, and working with @scottfrazer, I think we understand what’s going on. This doesn’t appear to be a Notehub bug.
Recommended Actions:
- Enable only 1 Thingspeak route in Notehub per Thingspeak API key
- Set the Route Requests per second configuration to
0.066
Why only 1 Thingspeak Route?
Our understanding is Thingspeak rate limits incoming requests per API key. Rate limiting of requests performed by Notehub routes is done per route. This means if you have more than one Notehub route pointing to Thingspeak, if they both end up executing with the same 15 second window, one of them will succeed and one will fail. To prevent this, use a single Notehub route for the same Thingspeak API key.
Why do we think it’s a rate limit issue?
The Thingspeak endpoint will return a 0 for requests that were not processed. This could be for any number of reasons including violating the rate limiting, or providing an incorrect API key. The unfortunate thing from Notehub’s point of view is Thingspeak returns an HTTP status code of 200, which indicates a successful transaction. So Notehub thinks it was successful, but the data won’t appear in Thingspeak channel.
Normally this type of error would return a 429 for rate limit violations or 401 unauthorized …or literally anything other than a code that is in the 200’s.
In addition, since we see there are multiple routes pointing to the same Thingspeak endpoint, and one will succeed, and the other can fail. This indicates that the data can get through, but may be denied if because one route has already executed in the 15 second time window.
Since the routes have the same rate configuration, why don’t they work the same?
The 2 routes are fundamentally different.
The one going directly to Thingspeak needs to abide by the Thingspeak API rate limit of 1 request every 15 seconds. In the Notehub route this is 0.066 requests per second (this just over 15 seconds between requests, but it will get saturated to 15 seconds by Notehub under the hood)
The one going to the leaky bucket algorithm doesn’t require any rate limiting. That’s by design. The purpose of the leaky bucket is to convert burst data transmissions into a series of requests occurring at a uniform rate. The leaky bucket imposes the rate limit, not Notehub.
Wasn’t there a bug in the leaky bucket?
Yes, the leaky bucket implementation we provided did have a bug in it. Though that may not have actually prevented data from reaching Thingspeak.
The primary issue is the API rate limit was being exceeded because the Thingspeak API had already been called via the same API key within the 15 second window by a different Notehub route. This conflict of course could appear somewhat random, and may be exacerbated by the fact that multiple messages from the Notecard may have been uploaded to Notehub in the same sync from Notecard, which would have resulted in more Thingspeak API calls.
Hope this helps!