Skip to content

Instantly share code, notes, and snippets.

@naile
Last active March 19, 2018 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naile/925eff8e83e70b20f21841d5081c06f6 to your computer and use it in GitHub Desktop.
Save naile/925eff8e83e70b20f21841d5081c06f6 to your computer and use it in GitHub Desktop.
set dotnet IOCP/worker threads for Redis
public static class ConfigureIoThreads
{
private static int IOCPThreadsMin = Environment.ProcessorCount * 4;
private static int WorkerThreadsMin = Environment.ProcessorCount * 2;
//https://gist.github.com/JonCole/e65411214030f0d823cb#file-threadpool-md
public static void ForRedis(ILogger logger)
{
// get the current settings.
ThreadPool.GetMinThreads(out int currentMinWorker, out int currentMinIOC);
logger.LogDebug("Current configuration value for IOCP = {IOCP} and WORKER = {WORKER}", currentMinIOC, currentMinWorker);
// min worker/iocp threads to set
var iocpThreads = Math.Max(currentMinIOC, IOCPThreadsMin);
var workerThreads = Math.Max(currentMinWorker, WorkerThreadsMin);
// set min worker/iocp threads
ThreadPool.SetMinThreads(workerThreads, iocpThreads);
logger.LogDebug("Minimum configuration value set for IOCP = {IOCP} and WORKER = {WORKER}", iocpThreads, workerThreads);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment