Similar Posts

4 Comments

  1. Thank you for a great insightful post.
    We had a similar issue in our APIs. So we have implemented the suggested workaround by increasing the minimum threads to 100.
    In our development environment, it has increased the minimum threads to 100 as shown in the below api response

    {
    “minWorkerThreads”: 100,
    “minCompletionPortThreads”: 100,
    “maxWorkerThreads”: 32767,
    “maxCompletionPortThreads”: 1000
    }

    But the same code, when we push to prod, it is not being updated to 100 and it is still 16 as shown in the below response in prod.

    {
    “minWorkerThreads”: 16,
    “minCompletionPortThreads”: 100,
    “maxWorkerThreads”: 32767,
    “maxCompletionPortThreads”: 1000
    }

    Could you please help us as to why it is not being updated in prod.

    Thanks In Advance
    Pramod

    1. Try setting it in the runtimeconfig.json file as shown below
      {
      “runtimeOptions”: {
      “configProperties”: {
      “System.Threading.ThreadPool.MinThreads”: 100
      }
      }
      }

  2. One small correction:

    “On my machine CPU configuration shows a total of 6 Core with 12 logical processors i.e. 2 threads per core i.e. a total of 12 threads at the hardware level. So ASP.NET Core applications on my machine should start with 12 default minimum threads.”

    MinThreads does not mean the minimum number of threads that will be allocated when you applications starts. It means the minimum number of threads that the ThreadPool will allocate without any throttling.

    So let’s say MinThreads = 12, in your example. Your application starts up and is ready to receive requests. At this stage there are not 12 threads allocated to your application. There may be one or more threads allocated, depending on what your application does while it’s idling. Requests start coming in and new threads are allocated to handle the requests. The first 12 threads will be allocated without delay, assuming your CPU is not throttled. Let’s say a new request comes while the first 12 threads are still busy, and so a 13th thread needs to be allocated. Because 13 > 12 (MinThreads), the ThreadPool manager will wait 500ms before allocating the 13th thread. This throttling behaviour is to ensure that a burst of requests don’t allocate too many threads too quickly, which could throttle the CPU

Leave a Reply

Your email address will not be published. Required fields are marked *