Commit 0c38d78d authored by justcoding121's avatar justcoding121

get connection per http session when pool is enabled

parent 8bd7872f
...@@ -57,6 +57,7 @@ namespace Titanium.Web.Proxy ...@@ -57,6 +57,7 @@ namespace Titanium.Web.Proxy
{ {
var cancellationToken = cancellationTokenSource.Token; var cancellationToken = cancellationTokenSource.Token;
var prefetchTask = prefetchConnectionTask;
TcpServerConnection serverConnection = null; TcpServerConnection serverConnection = null;
bool closeServerConnection = false; bool closeServerConnection = false;
...@@ -182,9 +183,9 @@ namespace Titanium.Web.Proxy ...@@ -182,9 +183,9 @@ namespace Titanium.Web.Proxy
bool newConnection = false; bool newConnection = false;
if (serverConnection == null && prefetchConnectionTask != null) if (serverConnection == null && prefetchTask != null)
{ {
serverConnection = await prefetchConnectionTask; serverConnection = await prefetchTask;
newConnection = true; newConnection = true;
} }
...@@ -207,9 +208,6 @@ namespace Titanium.Web.Proxy ...@@ -207,9 +208,6 @@ namespace Titanium.Web.Proxy
} }
//for connection pool retry fails until cache is exhausted //for connection pool retry fails until cache is exhausted
//In future once connection pool becomes stable
//we can get connection for each HTTP session instead of per client connection
//That will be more efficient especially when client is holding connection but not using it
int attempt = 0; int attempt = 0;
while (attempt < MaxCachedConnections + 1) while (attempt < MaxCachedConnections + 1)
{ {
...@@ -264,6 +262,16 @@ namespace Titanium.Web.Proxy ...@@ -264,6 +262,16 @@ namespace Titanium.Web.Proxy
{ {
throw new Exception("Session was terminated by user."); throw new Exception("Session was terminated by user.");
} }
//With connection pool get connection for each HTTP session instead of per client connection.
//That will be more efficient especially when client is holding connection but not using it
if (EnableConnectionPool)
{
await tcpConnectionFactory.Release(serverConnection);
serverConnection = null;
prefetchTask = null;
}
} }
catch (Exception e) when (!(e is ProxyHttpException)) catch (Exception e) when (!(e is ProxyHttpException))
{ {
......
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