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

Fixed Token Bucket Implementation #5

Open
jmawebtech opened this issue Jul 12, 2016 · 1 comment
Open

Fixed Token Bucket Implementation #5

jmawebtech opened this issue Jul 12, 2016 · 1 comment

Comments

@jmawebtech
Copy link

Hi,

I am using your tool to throttle orders from Amazon. Here are the parameters:

    //Loop through them calling GetOrder, since GetOrder has a max request quota of 6 with a refill rate of 1 a minute, with the added benefit of being able to call up to 50 orders per request. This means that I can make an initial request for 300 orders, then I must throttle down to 1 request a minute, requiring an additional 14 minutes for the remaining 700 orders.

    //For each order, I must call ListOrderItems. This has a max request limit of 30 and a restore rate of 1 every 2 seconds. This means that I can initially make 30 requests, then I must throttle to 1 every 2 seconds, which means it would take me about 485 seconds (or 8 minutes) to finish getting the order items for the rest of the orders.

Here is my code:

        listOrderRequestBucket = new FixedTokenBucket(6, 60, 1000);
        listOrderItemsRequestBucket = new FixedTokenBucket(1, 2, 1000);
        listFinancialEventsResponseBucket = new FixedTokenBucket(1, 2, 1000);

When I am throttled, I do this:

                    Timespan WaitTime;
                    bool shouldThrottle = listOrderRequestBucket.ShouldThrottle(1, out waitTime);

                    if (shouldThrottle)
                    {
                        Thread.Sleep(waitTime);
                        listOrderRequestBucket = new FixedTokenBucket(1, 60, 1000);
                    }

Is this what you recommend?

@zaus
Copy link

zaus commented Dec 12, 2016

I think you want the StepUpLeakyTokenBucket instead? (or maybe the StepDown per #6)

But for any strategy, the basic pattern is something like:

while(doIHaveMoreActions()) {
	myAction();
	while (yourBucket.ShouldThrottle(n, out snooze)) Thread.Sleep(snooze);
}

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

No branches or pull requests

2 participants