Last active
January 15, 2016 01:17
-
-
Save darbio/fc784b22710c082c4b95 to your computer and use it in GitHub Desktop.
IIS Express Threadpool Exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int workers; | |
int completions; | |
System.Threading.ThreadPool.GetMaxThreads(out workers, out completions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When webengine4.dll first starts, it sets the max thread pool size to an artificially low number, and it depends | |
// on System.Web.dll to set it back. Since we're replacing System.Web.dll, we need to perform this fixup manually. | |
// For now we'll use 100 * numCPUs. | |
int newLimits = 100 * Environment.ProcessorCount; // this is actually # cores (including hyperthreaded cores) | |
int existingMaxWorkerThreads; | |
int existingMaxIocpThreads; | |
ThreadPool.GetMaxThreads(out existingMaxWorkerThreads, out existingMaxIocpThreads); | |
ThreadPool.SetMaxThreads(Math.Max(newLimits, existingMaxWorkerThreads), Math.Max(newLimits, existingMaxIocpThreads)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Startup() | |
{ | |
#if DEBUG | |
// HACK | |
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "iisexpress") | |
{ | |
// Set worker threads as Helios sets them too low for IIS Express | |
// https://github.com/aspnet/Home/issues/94 | |
int newLimits = 100 * Environment.ProcessorCount; // this is actually # cores (including hyperthreaded cores) | |
int existingMaxWorkerThreads; | |
int existingMaxIocpThreads; | |
System.Threading.ThreadPool.GetMaxThreads(out existingMaxWorkerThreads, out existingMaxIocpThreads); | |
System.Threading.ThreadPool.SetMaxThreads(Math.Max(newLimits, existingMaxWorkerThreads), Math.Max(newLimits, existingMaxIocpThreads)); | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment