Commit 61da8091 authored by justcoding121's avatar justcoding121

Merge branch 'master' into beta

parents a285a45b f225e38d
This diff is collapsed.
......@@ -3505,19 +3505,6 @@ references:
isSpec: "True"
fullName: Titanium.Web.Proxy.ProxyServer.EnableTcpServerConnectionPrefetch
nameWithType: ProxyServer.EnableTcpServerConnectionPrefetch
- uid: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
name: EnableThreadPoolOptimizing
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableThreadPoolOptimizing
commentId: P:Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
fullName: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
nameWithType: ProxyServer.EnableThreadPoolOptimizing
- uid: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing*
name: EnableThreadPoolOptimizing
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableThreadPoolOptimizing_
commentId: Overload:Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
isSpec: "True"
fullName: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
nameWithType: ProxyServer.EnableThreadPoolOptimizing
- uid: Titanium.Web.Proxy.ProxyServer.EnableWinAuth
name: EnableWinAuth
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableWinAuth
......@@ -3828,6 +3815,19 @@ references:
isSpec: "True"
fullName: Titanium.Web.Proxy.ProxyServer.TcpTimeWaitSeconds
nameWithType: ProxyServer.TcpTimeWaitSeconds
- uid: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
name: ThreadPoolWorkerThread
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_ThreadPoolWorkerThread
commentId: P:Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
fullName: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
nameWithType: ProxyServer.ThreadPoolWorkerThread
- uid: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread*
name: ThreadPoolWorkerThread
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_ThreadPoolWorkerThread_
commentId: Overload:Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
isSpec: "True"
fullName: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
nameWithType: ProxyServer.ThreadPoolWorkerThread
- uid: Titanium.Web.Proxy.ProxyServer.UpStreamEndPoint
name: UpStreamEndPoint
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_UpStreamEndPoint
......
......@@ -72,8 +72,8 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="StreamExtended, Version=1.0.190.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
<HintPath>..\..\src\packages\StreamExtended.1.0.190\lib\net45\StreamExtended.dll</HintPath>
<Reference Include="StreamExtended, Version=1.0.201.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
<HintPath>..\..\src\packages\StreamExtended.1.0.201\lib\net45\StreamExtended.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="StreamExtended" version="1.0.190" targetFramework="net45" />
<package id="StreamExtended" version="1.0.201" targetFramework="net45" />
</packages>
\ No newline at end of file
......@@ -154,8 +154,13 @@ namespace Titanium.Web.Proxy
if (EnableTcpServerConnectionPrefetch)
{
//make sure the host can be resolved before creating the prefetch task
var ipAddresses = await Dns.GetHostAddressesAsync(connectArgs.HttpClient.Request.RequestUri.Host);
IPAddress[] ipAddresses = null;
try
{
//make sure the host can be resolved before creating the prefetch task
ipAddresses = await Dns.GetHostAddressesAsync(connectArgs.HttpClient.Request.RequestUri.Host);
}
catch (SocketException) { }
if (ipAddresses != null && ipAddresses.Length > 0)
{
......
......@@ -57,11 +57,7 @@ namespace Titanium.Web.Proxy
/// </summary>
private WinHttpWebProxyFinder systemProxyResolver;
/// <summary>
/// lock for Thread Pool tuning
/// </summary>
private object lockThreadPoolTuning = new object();
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of ProxyServer class with provided parameters.
......@@ -178,12 +174,6 @@ namespace Titanium.Web.Proxy
/// </summary>
public bool EnableTcpServerConnectionPrefetch { get; set; } = true;
/// <summary>
/// Gets or sets a Boolean value that specifies whether ThreadPool grows new connections and decrease when connections close
/// Defaults to true.
/// </summary>
public bool EnableThreadPoolOptimizing { get; set; } = true;
/// <summary>
/// Gets or sets a Boolean value that specifies whether server and client stream Sockets are using the Nagle algorithm.
/// Defaults to true, no nagle algorithm is used.
......@@ -363,6 +353,11 @@ namespace Titanium.Web.Proxy
/// </summary>
public event AsyncEventHandler<TcpClient> OnServerConnectionCreate;
/// <summary>
/// Customize the minimum ThreadPool size (increase it on a server)
/// </summary>
public int ThreadPoolWorkerThread { get; set; } = Environment.ProcessorCount;
/// <summary>
/// Add a proxy end point.
/// </summary>
......@@ -555,6 +550,8 @@ namespace Titanium.Web.Proxy
throw new Exception("Proxy is already running.");
}
setThreadPoolMinThread(ThreadPoolWorkerThread);
if (ProxyEndPoints.OfType<ExplicitProxyEndPoint>().Any(x => x.GenericCertificate == null))
{
CertificateManager.EnsureRootCertificate();
......@@ -732,19 +729,9 @@ namespace Titanium.Web.Proxy
if (tcpClient != null)
{
setThreadPoolMinThread(1); // increase the ThreadPool
Task.Run(async () =>
{
try
{
await handleClient(tcpClient, endPoint);
}
finally
{
setThreadPoolMinThread(-1); //decrease the Threadpool
}
await handleClient(tcpClient, endPoint);
});
}
......@@ -752,36 +739,24 @@ namespace Titanium.Web.Proxy
endPoint.Listener.BeginAcceptTcpClient(onAcceptConnection, endPoint);
}
private Lazy<int> maxWorkerThreads = new Lazy<int>(() =>
{
int maxWorkerThreads;
ThreadPool.GetMaxThreads(out maxWorkerThreads, out var _);
return maxWorkerThreads;
});
/// <summary>
/// Change the ThreadPool.WorkerThread minThread
/// </summary>
/// <param name="workerThreadsToAdd">Number of threads to add</param>
private void setThreadPoolMinThread(int workerThreadsToAdd)
/// <param name="workerThreadsToAdd">minimum Threads allocated in the ThreadPool</param>
private void setThreadPoolMinThread(int workerThreads)
{
if (EnableThreadPoolOptimizing)
{
lock (lockThreadPoolTuning)
{
int minWorkerThreads, minCompletionPortThreads;
int minWorkerThreads, minCompletionPortThreads, maxWorkerThreads;
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
minWorkerThreads = Math.Max(minWorkerThreads + workerThreadsToAdd, Environment.ProcessorCount);
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
ThreadPool.GetMaxThreads(out maxWorkerThreads, out _);
if (minWorkerThreads <= maxWorkerThreads.Value)
{
ThreadPool.SetMinThreads(minWorkerThreads, minCompletionPortThreads);
}
}
}
minWorkerThreads = Math.Min(maxWorkerThreads, Math.Max(workerThreads, Environment.ProcessorCount));
ThreadPool.SetMinThreads(minWorkerThreads, minCompletionPortThreads);
}
/// <summary>
/// Handle the client.
/// </summary>
......
......@@ -13,9 +13,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.1" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.3.37" />
<PackageReference Include="StreamExtended" Version="1.0.190" />
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="StreamExtended" Version="1.0.201" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
......
......@@ -15,14 +15,14 @@
<tags></tags>
<dependencies>
<group targetFramework="net45">
<dependency id="StreamExtended" version="1.0.190" />
<dependency id="Portable.BouncyCastle" version="1.8.3.37" />
<dependency id="BrotliSharpLib" version="0.3.1" />
<dependency id="StreamExtended" version="1.0.201" />
<dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="BrotliSharpLib" version="0.3.3" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="StreamExtended" version="1.0.190" />
<dependency id="Portable.BouncyCastle" version="1.8.3.37" />
<dependency id="BrotliSharpLib" version="0.3.1" />
<dependency id="StreamExtended" version="1.0.201" />
<dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Microsoft.Win32.Registry" version="4.4.0" />
<dependency id="System.Security.Principal.Windows" version="4.4.1" />
</group>
......
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