Two rate limiters in same pipeline #2341
-
I need to throttle requests to some external API: 14 requests per second and 50k requests per day. I tried to chain two var resiliencePipeline = new ResiliencePipelineBuilder()
.AddRateLimiter(new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions {
PermitLimit = 14,
QueueLimit = 0,
Window = TimeSpan.FromSeconds(1),
QueueProcessingOrder = QueueProcessingOrder.OldestFirst
}))
.AddRateLimiter(new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions {
PermitLimit = 50_000,
QueueLimit = 0,
Window = TimeSpan.FromDays(1),
QueueProcessingOrder = QueueProcessingOrder.OldestFirst
}))
.Build();
var result = await resiliencePipeline.ExecuteAsync(
token => DoWork(args),
cancellationToken); That seemed to prefer the second one; I guess the latter configuration overrides the former. Can Polly somehow keep track of both limits for me, or is that something I must handle manually? |
Beta Was this translation helpful? Give feedback.
Answered by
martincostello
Oct 12, 2024
Replies: 1 comment 4 replies
-
You need to create a chained rate limiter and give that to Polly. Then it's an implementation detail of the rate limiter itself, and Polly just needs one rate limit. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this should work for you: