Skip to content

Instantly share code, notes, and snippets.

@jstemerdink
Last active July 6, 2020 13:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstemerdink/52616c936014564071396a1a0a59be5e to your computer and use it in GitHub Desktop.
Save jstemerdink/52616c936014564071396a1a0a59be5e to your computer and use it in GitHub Desktop.

A little optimalization

Read my blog here

Powered by ReSharper image

public class Global : EPiServer.Global
{
protected void Application_Start()
{
// Other stuff here
// See: https://support.microsoft.com/en-gb/help/821268/contention-poor-performance-and-deadlocks-when-you-make-calls-to-web-s
// See: https://docs.microsoft.com/en-us/azure/redis-cache/cache-faq
SetMinThreads();
SetMaxThreads();
}
private static void SetMinThreads()
{
int workerThreads = string.IsNullOrEmpty(ConfigurationManager.AppSettings["WORKER_THREADS"])
? 50
: Convert.ToInt32(ConfigurationManager.AppSettings["WORKER_THREADS"]);
int iocpThreads = string.IsNullOrEmpty(ConfigurationManager.AppSettings["IOCP_THREADS"])
? 50
: Convert.ToInt32(ConfigurationManager.AppSettings["IOCP_THREADS"]);
ThreadPool.SetMinThreads(workerThreads, iocpThreads);
}
private static void SetMaxThreads()
{
int workerThreads = string.IsNullOrEmpty(ConfigurationManager.AppSettings["MAX_WORKER_THREADS"])
? 100
: Convert.ToInt32(ConfigurationManager.AppSettings["MAX_WORKER_THREADS"]);
int iocpThreads = string.IsNullOrEmpty(ConfigurationManager.AppSettings["MAX_IOCP_THREADS"])
? 100
: Convert.ToInt32(ConfigurationManager.AppSettings["MAX_IOCP_THREADS"]);
ThreadPool.SetMaxThreads(workerThreads, iocpThreads);
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="WORKER_THREADS" value="50" />
<add key="IOCP_THREADS" value="50" />
<add key="MAX_WORKER_THREADS" value="100" />
<add key="MAX_IOCP_THREADS" value="100" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" maxRequestLength="1048576" executionTimeout="900" minFreeThreads="352" minLocalRequestFreeThreads="304"/>
</system.web>
<system.net>
<connectionManagement>
<add address="*" maxconnection="48" />
</connectionManagement>
</system.net>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment