Make it possible to set worker/iocp min/max threadpool limits on the fly with the console command "debug threadpool set"

TeleportWork
Justin Clark-Casey (justincc) 2013-08-05 23:04:36 +01:00
parent 24dcf3cf6a
commit 160659f683
1 changed files with 78 additions and 0 deletions

View File

@ -256,6 +256,12 @@ namespace OpenSim.Framework.Servers
"Show thread status. Synonym for \"show threads\"", "Show thread status. Synonym for \"show threads\"",
(string module, string[] args) => Notice(GetThreadsReport())); (string module, string[] args) => Notice(GetThreadsReport()));
m_console.Commands.AddCommand (
"Debug", false, "debug threadpool set",
"debug threadpool set worker|iocp min|max <n>",
"Set threadpool parameters. For debug purposes.",
HandleDebugThreadpoolSet);
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"General", false, "force gc", "General", false, "force gc",
"force gc", "force gc",
@ -283,6 +289,78 @@ namespace OpenSim.Framework.Servers
m_serverStatsCollector.Start(); m_serverStatsCollector.Start();
} }
private void HandleDebugThreadpoolSet(string module, string[] args)
{
if (args.Length != 6)
{
Notice("Usage: debug threadpool set worker|iocp min|max <n>");
return;
}
int newThreads;
if (!ConsoleUtil.TryParseConsoleInt(m_console, args[5], out newThreads))
return;
string poolType = args[3];
string bound = args[4];
bool fail = false;
int workerThreads, iocpThreads;
if (poolType == "worker")
{
if (bound == "min")
{
ThreadPool.GetMinThreads(out workerThreads, out iocpThreads);
if (!ThreadPool.SetMinThreads(newThreads, iocpThreads))
fail = true;
}
else
{
ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
if (!ThreadPool.SetMaxThreads(newThreads, iocpThreads))
fail = true;
}
}
else
{
if (bound == "min")
{
ThreadPool.GetMinThreads(out workerThreads, out iocpThreads);
if (!ThreadPool.SetMinThreads(workerThreads, newThreads))
fail = true;
}
else
{
ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
if (!ThreadPool.SetMaxThreads(workerThreads, newThreads))
fail = true;
}
}
if (fail)
{
Notice("ERROR: Could not set {0} {1} threads to {2}", poolType, bound, newThreads);
}
else
{
int minWorkerThreads, maxWorkerThreads, minIocpThreads, maxIocpThreads;
ThreadPool.GetMinThreads(out minWorkerThreads, out minIocpThreads);
ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxIocpThreads);
Notice("Min worker threads now {0}", minWorkerThreads);
Notice("Min IOCP threads now {0}", minIocpThreads);
Notice("Max worker threads now {0}", maxWorkerThreads);
Notice("Max IOCP threads now {0}", maxIocpThreads);
}
}
private void HandleForceGc(string module, string[] args) private void HandleForceGc(string module, string[] args)
{ {
Notice("Manually invoking runtime garbage collection"); Notice("Manually invoking runtime garbage collection");