File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Configuration ;
3
+ using System . Threading ;
1
4
using System . Web ;
2
5
using System . Web . Mvc ;
3
6
using System . Web . Routing ;
@@ -25,6 +28,7 @@ private void Start()
25
28
{
26
29
Routes ( ) ;
27
30
Views ( ) ;
31
+ Threads ( ) ;
28
32
}
29
33
30
34
private void Routes ( )
@@ -57,6 +61,25 @@ private void Views()
57
61
ViewEngines . Engines . Add ( new RazorViewEngine { ViewLocationFormats = new [ ] { "~/Views/{0}.cshtml" } } ) ;
58
62
}
59
63
64
+ private void Threads ( )
65
+ {
66
+ // To improve CPU utilization, increase the number of threads that the .NET thread pool expands by when
67
+ // a burst of requests come in. We could do this by editing machine.config/system.web/processModel/minWorkerThreads,
68
+ // but that seems too global a change, so we do it in code for just our AppPool. More info:
69
+ //
70
+ // http://support.microsoft.com/kb/821268
71
+ // http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx
72
+ // http://blogs.msdn.com/b/perfworld/archive/2010/01/13/how-can-i-improve-the-performance-of-asp-net-by-adjusting-the-clr-thread-throttling-properties.aspx
73
+
74
+ int newMinWorkerThreads = Convert . ToInt32 ( ConfigurationManager . AppSettings [ "minWorkerThreadsPerLogicalProcessor" ] ) ;
75
+ if ( newMinWorkerThreads > 0 )
76
+ {
77
+ int minWorkerThreads , minCompletionPortThreads ;
78
+ ThreadPool . GetMinThreads ( out minWorkerThreads , out minCompletionPortThreads ) ;
79
+ ThreadPool . SetMinThreads ( Environment . ProcessorCount * newMinWorkerThreads , minCompletionPortThreads ) ;
80
+ }
81
+ }
82
+
60
83
public void Dispose ( )
61
84
{
62
85
}
Original file line number Diff line number Diff line change 29
29
<!-- Disable support for directly accessing *.cshtml/*.vbhtml files because that is a perf killer
30
30
and because we don't use such functionality. -->
31
31
<add key =" webpages:Enabled" value =" false" />
32
+ <!-- To fully saturate the CPUs, we need to allow the .NET thread pool to create many threads
33
+ when a large burst of requests come in. We do this by boosting the minWorkerThreads value
34
+ from the default of 1 per logical processor to 8 per logical processor. This seems to be
35
+ pretty conservative as http://support.microsoft.com/kb/821268 recommends 50.-->
36
+ <add key =" minWorkerThreadsPerLogicalProcessor" value =" 8" />
32
37
</appSettings >
33
38
<system .web>
34
39
<!-- Show errors -->
You can’t perform that action at this time.
0 commit comments