Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More gracefully handle exceeding the API limit. #985

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thailyn
Copy link
Contributor

@thailyn thailyn commented Mar 11, 2019

I've started using other tools that use SESSIONID, alongside Procurement. They don't play well together. This is an initial stab at making Procurement work better when it unexpectedly encounters 429 errors from the GGG API.

@aydjay
Copy link
Contributor

aydjay commented Mar 11, 2019

I have been meaning to implment Polly:

http://www.thepollyproject.org/

Instead of maintaining our own throttling mechanism. Would recquire a bit of a rework but I think it would be worth it in the longer term.

I had a stab at it but I got distracted xD

See: https://github.com/aydjay/Procurement/tree/poly

@Stickymaddness
Copy link
Member

The responses and request restrictions around the trade API have changed significantly since we last updated it in Procurement, details here.

If we're going to refactor Procurement's throttling code, then I'd like to take this into account since we can now actually know up front if we should throttle back or not.

@thailyn
Copy link
Contributor Author

thailyn commented May 7, 2019

If I'm not mistaken, those rate-limiting headers are for the trade API, which appears to be separate from the stash/inventory requests Procurement makes.

On the other hand, Procurement handles the current rate limits well; that is, our current values are still the most aggressive we can be without getting throttled. (I have been using this PR locally, and when I have another tool make API requests at the same time Procurement is, Procurement is throttled very quickly and reliably, which means Procurement fully utilizes the allowed request limits, but is never throttled when running by itself.)

@thailyn
Copy link
Contributor Author

thailyn commented Jun 13, 2019

@Stickymaddness , could we merge this PR? I know there are additional, more complex, features we could add to the throttler, but this is a simple code change that greatly improves Procurement's behavior in cases where it does go over the API limit (which, as I said, does not happen during the normal operation of Procurement in isolation).

If another tool that uses the GGG API is used alongside Procurement, it
is very easy to exceed the API limit.  This change more gracefully
handles that case, but is very cautious about it.  If an overflow is
detected, completely fill up the window of active tasks, and wait for at
least as long as the window size.
HttpWebResponse response = null;
// TODO: Don't retry an infinite number of times.
bool retry = true;
while (retry)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we at least make this a controlled number of attempts, rather than an infinite loop.

@Stickymaddness
Copy link
Member

I have a lot of reservations about this change, given that it's essentially adding support for running it alongside other applications, as common as that may be these days.

Precomputing the throttling as we are currently isn't the best way to go about it either.

The headers I linked in a previous comment come back for all requests, not just the ones mentioned in the documentation, and is the correct way of handling the throttling. But, this is unfortunately not something that I have time to implement myself.

Can we at least find a smarter way to handle the retries, and not loop indefinitely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants