How to troubleshoot thread starvation in ASP.NET Core on Linux (Kubernetes)? : <p>I'm running an ASP.NET Core API on Linux, on Kubernetes in the Google Cloud.</p>

<p>This is an API with high load, and on every request it's executing a library doing a long (1-5 seconds), CPU-intensive operation.</p>

<p>What I see is that after deployment the API works properly for a while, but after 10-20 minutes it becomes unresponsive, and even the health check endpoint (which just returns a hardcoded <code>200 OK</code>) stops working and times out. (This makes Kubernetes kill the pods.)</p>

<p>Sometimes I'm also seeing the infamous <code>Heartbeat took longer than "00:00:01"</code> error message in the logs.</p>

<p>Googling these phenomenons points me to "Thread starvation", so that there are too many thread pool threads started, or too many threads are blocking waiting on something, so that there are no threads left in the pool which could pick up ASP.NET Core requests (hence the timeout of even the health check endpoint).</p>

<p>What is the best way to troubleshoot this issue? I started monitoring the numbers returned by <code>ThreadPool.GetMaxThreads</code> and <code>ThreadPool.GetAvailableThreads</code>, but they stayed constant (the completion port is always <code>1000</code> both for max and available, and the worker is always <code>32767</code>).<br>
Is there any other property I should monitor?</p>
