Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
45b13d34
Unverified
Commit
45b13d34
authored
May 14, 2018
by
justcoding121
Committed by
GitHub
May 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #443 from justcoding121/master
Cache improvements
parents
e1f03c43
022b4762
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
25 deletions
+44
-25
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+44
-25
No files found.
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
45b13d34
...
@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
$"
{
isHttps
}
-"
);
$"
{
isHttps
}
-"
);
if
(
applicationProtocols
!=
null
)
if
(
applicationProtocols
!=
null
)
{
{
foreach
(
var
protocol
in
applicationProtocols
.
OrderBy
(
x
=>
x
))
foreach
(
var
protocol
in
applicationProtocols
.
OrderBy
(
x
=>
x
))
{
{
cacheKeyBuilder
.
Append
(
$"
{
protocol
}
-"
);
cacheKeyBuilder
.
Append
(
$"
{
protocol
}
-"
);
}
}
...
@@ -94,9 +94,15 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -94,9 +94,15 @@ namespace Titanium.Web.Proxy.Network.Tcp
if
(
proxyServer
.
EnableConnectionPool
)
if
(
proxyServer
.
EnableConnectionPool
)
{
{
try
{
await
@lock
.
WaitAsync
();
if
(
cache
.
TryGetValue
(
cacheKey
,
out
var
existingConnections
))
if
(
cache
.
TryGetValue
(
cacheKey
,
out
var
existingConnections
))
{
{
while
(
existingConnections
.
TryDequeue
(
out
var
recentConnection
))
while
(
existingConnections
.
Count
>
0
)
{
if
(
existingConnections
.
TryDequeue
(
out
var
recentConnection
))
{
{
//+3 seconds for potential delay after getting connection
//+3 seconds for potential delay after getting connection
var
cutOff
=
DateTime
.
Now
.
AddSeconds
(-
1
*
proxyServer
.
ConnectionTimeOutSeconds
+
3
);
var
cutOff
=
DateTime
.
Now
.
AddSeconds
(-
1
*
proxyServer
.
ConnectionTimeOutSeconds
+
3
);
...
@@ -111,6 +117,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -111,6 +117,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
}
}
}
}
}
}
}
finally
{
@lock
.
Release
();
}
}
var
connection
=
await
createClient
(
remoteHostName
,
remotePort
,
httpVersion
,
isHttps
,
var
connection
=
await
createClient
(
remoteHostName
,
remotePort
,
httpVersion
,
isHttps
,
applicationProtocols
,
isConnect
,
proxyServer
,
upStreamEndPoint
,
externalProxy
,
cancellationToken
);
applicationProtocols
,
isConnect
,
proxyServer
,
upStreamEndPoint
,
externalProxy
,
cancellationToken
);
...
@@ -181,7 +193,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -181,7 +193,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
foreach
(
var
item
in
cache
)
foreach
(
var
item
in
cache
)
{
{
var
queue
=
item
.
Value
;
var
queue
=
item
.
Value
;
while
(
queue
.
TryDequeue
(
out
var
connection
))
while
(
queue
.
Count
>
0
)
{
if
(
queue
.
TryDequeue
(
out
var
connection
))
{
{
var
cutOff
=
DateTime
.
Now
.
AddSeconds
(-
1
*
server
.
ConnectionTimeOutSeconds
);
var
cutOff
=
DateTime
.
Now
.
AddSeconds
(-
1
*
server
.
ConnectionTimeOutSeconds
);
if
(!
server
.
EnableConnectionPool
if
(!
server
.
EnableConnectionPool
...
@@ -195,6 +210,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -195,6 +210,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
break
;
break
;
}
}
}
}
}
try
try
{
{
...
@@ -212,13 +228,16 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -212,13 +228,16 @@ namespace Titanium.Web.Proxy.Network.Tcp
@lock
.
Release
();
@lock
.
Release
();
}
}
while
(
disposalBag
.
TryTake
(
out
var
connection
))
while
(!
disposalBag
.
IsEmpty
)
{
if
(
disposalBag
.
TryTake
(
out
var
connection
))
{
{
connection
?.
Dispose
();
connection
?.
Dispose
();
}
}
}
//cleanup every
ten
seconds by default
//cleanup every
3
seconds by default
await
Task
.
Delay
(
1000
*
10
);
await
Task
.
Delay
(
1000
*
3
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment