Last active
March 19, 2018 12:39
-
-
Save naile/925eff8e83e70b20f21841d5081c06f6 to your computer and use it in GitHub Desktop.
set dotnet IOCP/worker threads for Redis
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 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