Throttle Zaptec Cloud requests to avoid hitting rate limits (fixes #165)#190
Throttle Zaptec Cloud requests to avoid hitting rate limits (fixes #165)#190sveinse merged 2 commits intocustom-components:masterfrom
Conversation
|
Thank you for the contribution. This fits into the efforts to adopt to Zaptec API fair use policy as tracked in #188. The plans are to significantly reduce the polling interval. The policy hints at 60 minutes being reasonable, while we are using 60 seconds.
|
|
I believe the service bus is working, but is there a recommended way to verify that for sure? The main benefit of the rate limiter is that, currently, whenever an update is triggered, requests for all chargers are sent at the same time. This creates a burst of requests on every poll, regardless of the polling interval. It’s usually not an issue with a small number of chargers, but once you go beyond 5 or 6—like in my case, with around 30 chargers—it quickly leads to hitting rate limits. |
|
There are three sources of events/changes:
We definitely need a burst limiter like proposed, because atm I cannot see that we can be without polling. We definitely need to refactor a few things to be compliant with the API policy. Are you willing and able to test alpha/beta versions when they are available? I don't have access to more than one, so its hard to verify how it works with many. |
sveinse
left a comment
There was a problem hiding this comment.
When I think of it, it would have been nice if the rate limiter and the exponential backoff were a part of the same system. I wonder, does it exist something that provides both, or are we good by having them separate?
|
The current design in |
sveinse
left a comment
There was a problem hiding this comment.
I think this looks good. I've tested it and the throttling seems to work fine. I'd like to change a little bit on how the exponential back-off is implemented, but we'll do that in a follow-up PR. Approved.
|
Thank you for the contributions @feliciaan . Much appreciated. |
Hello
I was running into the same issue described in #165 when using multiple Zaptec chargers — getting frequent HTTP 429 errors (“Too Many Requests”).
To fix this, I added rate limiting using the aiolimiter package, which helps queue and throttle the number of requests sent. This keeps things within Zaptec’s allowed request limits and avoids spamming retries.
This fixes it on my system with 15 Zaptec chargers connected.