Robert
Robert

Reputation: 6437

Limiting the threads per processor using IIS 7.5

I’m running some performance tests on an ASP.NET MVC application. I see a high contention rate and the number of threads increasing overtime. I believe the two to be related, as threads are blocked new threads are created by the thread pool to handle incoming requests. I believe this in turn is making the contention worse (i.e. more threads more contention).

The correct approach is probably to take the cause of the contention, i.e. make the critical sections smaller, verify that all the locks are really needed etc. However, as an intermitted step I’d like to limit the number of threads that can be created by the thread pool. My belief is that all though this may lead to requests staying in the queue longer it will improve overall though put as it will reduce contention and thread context switching.

However, I can find how to configure this in IIS 7.5, can anyone help me?

Thanks, Rob

Upvotes: 2

Views: 8599

Answers (2)

Robert
Robert

Reputation: 6437

Did finally find how to do this on IIS 7.5 you need to add a CLRConfigFile attribute to the applicationHost.config (located in C:\Windows\System32\inetsrv\config).

    <add name="ASP.NET v4.0" CLRConfigFile="C:\code\ThreadLeakWebSite\apppool.config" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" />

You can then add the parameters restricting the number of threads to the apppool.config config you point to, i.e.:

<configuration>
    <system.web>
        <applicationPool maxConcurrentRequestsPerCPU="5000" maxConcurrentThreadsPerCPU="0" requestQueueLimit="5000"/>
    </system.web>
</configuration>

Upvotes: 3

spender
spender

Reputation: 120538

If possible, you could call ThreadPool.SetMaxThreads from code.

EDIT:

It seems a better place to make this change would be with the processModel/maxWorkerThreads property in the web.config file:

<configuration>
  <system.web>
    <processModel maxWorkerThreads="5"/>
...

Would mean max 5 threads per CPU.

Upvotes: 0

Related Questions