Avoiding Thread Pool Starvation #1260
-
We're currently considering using YARP as part of one of our projects. However, we have situations where we receive hundreds of thousands of concurrent connections within a few seconds. When this hits YARP or any other .NET software for that matter, it immediately obliterates the thread pool (thousands of threads) and results in an instant deadlock. Does anyone have any recommendations on how to tackle this? We can't really do much rate or connection limiting here. I've tried to implement some sort of worker/event-driven system, but it seems Kestrel alone is part of the problem. UnsafePreferInlineScheduling is also out of the question given that the requests do have async / long-running requests. Seems like YARP is not really suitable for very high load environments, unfortunately. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Out of curiosity: Which .NET version do you run on? The ThreadPool has been rewritten in .NET 6 - @kouvel can provide more info. On lower version of .NET, the ThreadPool (and YARP) can scale, it just takes incremental load increase to scale well. If there is spike, ThreadPool does not respond that well. There is a workaround to adjust |
Beta Was this translation helpful? Give feedback.
-
Thanks for the message. We use .NET 6.0 RC1. We set the following:
I did notice performance was significantly improved when going from 5.0 to 6.0, but it's these super large spikes that we can't quite work around. I've been thinking of using a concurrency control middleware to incrementally increase throughput if needed, but that seems like it's working around the problem. We did also notice there is a part of code that is somewhat CPU intensive, so we're also optimizing that at the moment to see if it helps. Perhaps one is related to the other. I guess we have a bit of an extreme environment. In rare cases, spikes of legitimate traffic reach up to a million connections in a few seconds. The issue is this then results in a lockup that usually only resolves itself with a restart of the app. |
Beta Was this translation helpful? Give feedback.
Out of curiosity: Which .NET version do you run on? The ThreadPool has been rewritten in .NET 6 - @kouvel can provide more info.
On lower version of .NET, the ThreadPool (and YARP) can scale, it just takes incremental load increase to scale well. If there is spike, ThreadPool does not respond that well. There is a workaround to adjust
ThreadPool.SetMinThreads
to match the needs of your workload if you expect certain load.Would that help your situation?