Skip to content

Instantly share code, notes, and snippets.

@darbio
Last active January 15, 2016 01:17
Show Gist options
  • Save darbio/fc784b22710c082c4b95 to your computer and use it in GitHub Desktop.
Save darbio/fc784b22710c082c4b95 to your computer and use it in GitHub Desktop.
IIS Express Threadpool Exceptions
int workers;
int completions;
System.Threading.ThreadPool.GetMaxThreads(out workers, out completions);
// 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));
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