Commit fe03b185 authored by Stéphane Graziano's avatar Stéphane Graziano
parents 65d5aa30 25b05f20
...@@ -1291,7 +1291,7 @@ Defaults via any IP addresses of this machine.</p> ...@@ -1291,7 +1291,7 @@ Defaults via any IP addresses of this machine.</p>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Dispose.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Dispose%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Dispose.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Dispose%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span> </span>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L890">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L907">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_ProxyServer_Dispose_" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose*"></a> <a id="Titanium_Web_Proxy_ProxyServer_Dispose_" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose*"></a>
<h4 id="Titanium_Web_Proxy_ProxyServer_Dispose" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose">Dispose()</h4> <h4 id="Titanium_Web_Proxy_ProxyServer_Dispose" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose">Dispose()</h4>
......
...@@ -732,13 +732,19 @@ namespace Titanium.Web.Proxy ...@@ -732,13 +732,19 @@ namespace Titanium.Web.Proxy
if (tcpClient != null) if (tcpClient != null)
{ {
SetThreadPoolMinThread(1); // increase the ThreadPool setThreadPoolMinThread(1); // increase the ThreadPool
Task.Run(async () => Task.Run(async () =>
{ {
await handleClient(tcpClient, endPoint); try
{
await handleClient(tcpClient, endPoint);
}
finally
{
setThreadPoolMinThread(-1); //decrease the Threadpool
}
SetThreadPoolMinThread(-1); //decrease the Threadpool
}); });
} }
...@@ -746,20 +752,32 @@ namespace Titanium.Web.Proxy ...@@ -746,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>
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);
}
} }
} }
} }
...@@ -774,8 +792,7 @@ namespace Titanium.Web.Proxy ...@@ -774,8 +792,7 @@ namespace Titanium.Web.Proxy
{ {
tcpClient.ReceiveTimeout = ConnectionTimeOutSeconds * 1000; tcpClient.ReceiveTimeout = ConnectionTimeOutSeconds * 1000;
tcpClient.SendTimeout = ConnectionTimeOutSeconds * 1000; tcpClient.SendTimeout = ConnectionTimeOutSeconds * 1000;
tcpClient.SendBufferSize = BufferSize;
tcpClient.ReceiveBufferSize = BufferSize;
tcpClient.LingerState = new LingerOption(true, TcpTimeWaitSeconds); tcpClient.LingerState = new LingerOption(true, TcpTimeWaitSeconds);
await InvokeConnectionCreateEvent(tcpClient, true); await InvokeConnectionCreateEvent(tcpClient, true);
......
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