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
5815b7b8
Unverified
Commit
5815b7b8
authored
Apr 04, 2019
by
Jehonathan Thomas
Committed by
GitHub
Apr 04, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #574 from StephaneGraziano/master
Add ThreadPool tuning for better performances when heavy load
parents
0f19fea8
1e2c1c92
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
1 deletion
+37
-1
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+37
-1
No files found.
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
5815b7b8
...
...
@@ -57,6 +57,11 @@ 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.
...
...
@@ -173,6 +178,12 @@ 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.
...
...
@@ -721,13 +732,38 @@ namespace Titanium.Web.Proxy
if
(
tcpClient
!=
null
)
{
Task
.
Run
(
async
()
=>
{
await
handleClient
(
tcpClient
,
endPoint
);
});
SetThreadPoolMinThread
(
1
);
// increase the ThreadPool
Task
.
Run
(
async
()
=>
{
await
handleClient
(
tcpClient
,
endPoint
);
SetThreadPoolMinThread
(-
1
);
//decrease the Threadpool
});
}
// Get the listener that handles the client request.
endPoint
.
Listener
.
BeginAcceptTcpClient
(
onAcceptConnection
,
endPoint
);
}
/// <summary>
/// Change the ThreadPool.WorkerThread minThread
/// </summary>
/// <param name="piNbWorkerThreadsToAdd">Number of threads to add</param>
void
SetThreadPoolMinThread
(
int
piNbWorkerThreadsToAdd
)
{
if
(
EnableThreadPoolOptimizing
)
{
lock
(
lockThreadPoolTuning
)
{
int
iWorkerThreads
,
iCompletionPortThreads
;
ThreadPool
.
GetMinThreads
(
out
iWorkerThreads
,
out
iCompletionPortThreads
);
iWorkerThreads
=
Math
.
Max
(
iWorkerThreads
+
piNbWorkerThreadsToAdd
,
Environment
.
ProcessorCount
);
ThreadPool
.
SetMinThreads
(
iWorkerThreads
,
iCompletionPortThreads
);
}
}
}
/// <summary>
/// Handle the client.
/// </summary>
...
...
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