Commit 54d3b2dd authored by justcoding121's avatar justcoding121

check for upper limit

parent 124443c5
...@@ -752,20 +752,32 @@ namespace Titanium.Web.Proxy ...@@ -752,20 +752,32 @@ namespace Titanium.Web.Proxy
endPoint.Listener.BeginAcceptTcpClient(onAcceptConnection, endPoint); endPoint.Listener.BeginAcceptTcpClient(onAcceptConnection, endPoint);
} }
private Lazy<int> maxWorkerThreads = new Lazy<int>(() =>
{
int maxWorkerThreads;
ThreadPool.GetMaxThreads(out maxWorkerThreads, out var _);
return maxWorkerThreads;
});
/// <summary> /// <summary>
/// Change the ThreadPool.WorkerThread minThread /// Change the ThreadPool.WorkerThread minThread
/// </summary> /// </summary>
/// <param name="piNbWorkerThreadsToAdd">Number of threads to add</param> /// <param name="workerThreadsToAdd">Number of threads to add</param>
private void setThreadPoolMinThread(int piNbWorkerThreadsToAdd) private void setThreadPoolMinThread(int workerThreadsToAdd)
{ {
if (EnableThreadPoolOptimizing) if (EnableThreadPoolOptimizing)
{ {
lock (lockThreadPoolTuning) lock (lockThreadPoolTuning)
{ {
int iWorkerThreads, iCompletionPortThreads; int minWorkerThreads, minCompletionPortThreads;
ThreadPool.GetMinThreads(out iWorkerThreads, out iCompletionPortThreads);
iWorkerThreads = Math.Max(iWorkerThreads + piNbWorkerThreadsToAdd, Environment.ProcessorCount); ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
ThreadPool.SetMinThreads(iWorkerThreads, iCompletionPortThreads); minWorkerThreads = Math.Max(minWorkerThreads + workerThreadsToAdd, Environment.ProcessorCount);
if (minWorkerThreads <= maxWorkerThreads.Value)
{
ThreadPool.SetMinThreads(minWorkerThreads, minCompletionPortThreads);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment