I am trying to implement rate limiting algorithm by Response handling pseudo code and have some questions about the pseudo code.
1)
If the server responds with status 429 and no Retry-After header, then the delay would be: 10sec, 20sec, 30sec, 30sec because:
I assume lastRetryDelay is set to initialRetryDelay, so the first delay is 2*5sec = 10sec.
maxRetryDelay is hit on the 3rd round already, should be initialRetryDelay lower?
No jitter, because the jitter is computed with retryAfterDelay only, is that right?
Especially the last point baffles me. I would do it other way. I think that retryAfterDelay is authoritative and does not need a jitter while computed delay should have a jitter added and not just min(2 * lastRetryDelay, maxRetryDelay).
2)
No handling of X-RateLimit-Reset, see Retry-After headers. Is that OK? Also, Retry-After may be a <http-date>, see MDN Retry-After. Does Jira API returns Retry-After as a <delay-seconds> only?
3)
The pseudo code does not explicitly computes retryAfterDelay, but is seems it’s assumed in [ms] while Retry-After header should be in [s]. Does Jira API returns Retry-After in [ms] or [s]?
Thanks for posing these questions. I wrote the pseudo code with the aim of trying to keep it generic and simple to understand, but it would be great to see contributions from the community.
Here are my responses to your questions:
Yes, lastRetryDelay should be initialised to initialRetryDelay - I’ll fix this. The code is designed to be tuned for different situations so UI operations probably shouldn’t have too many retries, but other non time-sensitive operations perhaps may deserve more retries. The jitter in the pseudo code isn’t clear - I’ll fix it.
I think it’s OK not to factor in the value of X-RateLimit-Reset, but maybe doing so would help optimise for certain cases. Happy to hear your thoughts on this.
The units of the value returned by the Retry-After header is seconds.
Thanks for quick answer and clarification. IMHO setting fixed retry time (either in X-RateLimit-Reset or in Retry-After) may be problematic because of clock synchronization problem. So, it’s simpler to avoid that if the Atlassian does not insist on that. (Also the question is, if and how often is this header field used in real retry limit answers.)
@dmorrow What about to use widely used JavaScript open source library ky and document it at the Rate limiting page? If some details or retry algorithm of this library are not aligned with the Atlassian rules, then we may create a feature request to the source repository to improve it.
Update: I’ve found several problems in ky retry algorithm and reported them to the author. It would be nice anyway if we would able to just use some JS library and go.
I believe the /rest/agile/{version}/board end point is an expensive operation and therefore more likely to return rate limit responses, but I’m not sure why you’re getting a 500 error - this seems like an error on Jira’s side. Are you able to raise an ECOHELP ticket for this.