Skip to content

Commit aae2ae8

Browse files
committed
Update rate limit
1 parent f306610 commit aae2ae8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

FortnoxSDK.Tests/RateLimiterTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ public async Task Test_RateLimiter_NoError()
3535
watch.Stop();
3636

3737
/*
38-
* Given the rate limiter of 4 requests per second,
39-
* 200 requests should be executed in ~50 seconds.
40-
* Note: time per request might be longer than 250ms, hence the longer maximum allowed elapsed time
38+
* Given the rate limiter of 4.8 requests per second (24/5),
39+
* 200 requests should be executed in ~41 seconds.
40+
*
41+
* If we can increase the rate limiter to the advertised 25/5 (5 per second),
42+
* 200 requests should be executed in ~40 seconds.
4143
*/
44+
4245
Assert.AreEqual(200, counter);
43-
Assert.IsTrue(watch.Elapsed.TotalSeconds is > 49 and < 65);
46+
Assert.IsTrue(watch.Elapsed.TotalSeconds is > 40);
4447
}
4548

4649
[Ignore("Can make other test fail due to exhausting rate limiter")]

FortnoxSDK/Connectors/Base/RateLimiter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace Fortnox.SDK.Connectors.Base;
88

99
/// <summary>
10-
/// Rate limit - 4 requests per 1 seconds per token
10+
/// Rate limit - 25 requests per 5 seconds per token
1111
/// </summary>
1212
internal class RateLimiter
1313
{
14-
private const int MaxCount = 4;
15-
private static readonly TimeSpan Period = TimeSpan.FromSeconds(1);
14+
private const int MaxCount = 24; // Rate limit is 25 requests over 5 second sliding window, but using the max allowed still seems to trigger the limit. 24 req per 5 sec seems to work consistently.
15+
private static readonly TimeSpan Period = TimeSpan.FromSeconds(5);
1616

1717
private static readonly Dictionary<string, TimeLimiter> RateLimiters = new();
1818

0 commit comments

Comments
 (0)