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

Incorrect token reset in StepUpLeakyTokenBucket #6

Open
zaus opened this issue Dec 12, 2016 · 1 comment
Open

Incorrect token reset in StepUpLeakyTokenBucket #6

zaus opened this issue Dec 12, 2016 · 1 comment

Comments

@zaus
Copy link

zaus commented Dec 12, 2016

Instead of

tokens = stepTokens;

should it be:

tokens = bucketTokenCapacity;

similar to the StepDownLeakyTokenBucket?

It might just be that I don't really understand the difference or how to use it, but when using the StepUp I always wait when calling throttle.ShouldWait, while the StepDown style will pass on the number of tokens before starting to wait.

@zaus
Copy link
Author

zaus commented Dec 12, 2016

I'm testing with something like:

// just to see what's happening while the throttle is snoozing...
var continueInterstitial = true;
var inBetweenLoops = 0;
var repeatLoops = 0;
var ct = new CancellationTokenSource();
var inBetween = Task.Run(() => {
	while( continueInterstitial )
	{
		Dump("	Loop {3}:{2} at {1} Interstitial: {0}", backoff, SystemTime.UtcNow, inBetweenLoops, repeatLoops);
		Thread.Sleep(stepDuration + 50);
		inBetweenLoops++;
		repeatLoops++;
	}
},
	ct.Token);

// the actual "test"
Func<int, Action<int>, TimeSpan> test = (repeat, inbetween) => {
	var start = SystemTime.UtcNow;
	log("Starting Test: {0:O} {1}", start, backoff);
	for (int i = 0; i < repeat; i++)
	{
		repeatLoops = 0;
		Dump("Try {0}: {1}", i, backoff);
		
		TimeSpan snooze;
		while (backoff.ShouldThrottle(1, out snooze)) Thread.Sleep(snooze);
		
		Dump("End Wait: {0:O} {1}", SystemTime.UtcNow, backoff);
		if (inbetween != null) inbetween(i);
	}
	var end = SystemTime.UtcNow;
	var result = end - start;
	Dump("Ended Test: {0:O} in {2} {1}", end, backoff, result);
	return result;
};


var duration = test(tries, null);
continueInterstitial = false;
ct.Cancel();

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

1 participant