question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rate limiter causes thread pool exhaustion

See original GitHub issue

When trying to load test the sliding window limiter I noticed that it quickly lead to redis timeouts especially in environments with limited cpu count and/or and a bit of latency to redis. This seems to be caused by exhausting the thread pool. Looking into the issue I found the following: The TryAcquireAsync function in RateLimitingMiddleware.cs first does a synchronous AttemptAcquire call before falling back to before falling back to AcquireAsync on the RateLimiter. This means unless something goes wrong, only synchronous StackExchange Redis calls are performed by this package.

Looking at the documentation on the RateLimiter class it says:

AcquireAsync(Int32, CancellationToken) Wait until the requested permits are available or permits can no longer be acquired.
AttemptAcquire(Int32) Fast synchronous attempt to acquire permits.

So this isn’t just the usual case of having an async and a blocking implementation but meant to be distinct functions that can both be used.

I have to admit that I am not sure I fully get the intent of the interface with regards to waiting until a permit is available. But I think the way to get proper scalability would probably be to never return a lease from the synchronous call and only reach out to redis in the asynchronous one.

Would this be an appropriate change? Bit surprised I am the first one to stumble over this so maybe I am on the wrong track completely.

Issue Analytics

  • State:open
  • Created 3 months ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cristipufucommented, Jul 10, 2023

We could overwrite these classes in the RedisRateLimiting.AspNetCore package 🤔

0reactions
kamilslusarczykcommented, Jul 10, 2023

For reference: related issue created in MS’s repo: https://github.com/dotnet/runtime/issues/88592

Read more comments on GitHub >

github_iconTop Results From Across the Web

What happens when you use Task.Run so much that ...
Run truly blocks, then Task.Run seems to be my only choice. Any advice on how to pushback on client requests to prevent thread...
Read more >
NET ThreadPool starvation, and how queuing makes it worse
Using a dedicated pool of threads around the blocking calls can help a lot, as you stop competing with the global queue for...
Read more >
IIS thread pool (Expert guide)
If you are hitting thread pool exhaustion, you can raise the limit by increasing MaxPoolThreads (per processor), and PoolThreadLimit (the absolute hard limit)....
Read more >
Diagnosing thread pool exhaustion issues in .NET Core apps
In this episode, Software Engineer, Mike Rousos, joins Rich to go through some ways to diagnose thread pool exhaustion in your .NET apps....
Read more >
Throttling Task Submission Rate in Java
In this example, throttling will help in keeping the number of tasks in queue in limit so that no task get rejected.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found