Skip to content

Commit acbcd03

Browse files
committed
Tune nº of working threads, add comments.
1 parent 68a4803 commit acbcd03

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

frameworks/CSharp/wiredio/src/Platform/Program.cs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
#pragma warning disable CA2014
1010

11+
/* (MDA2AV)Dev notes:
12+
*
13+
* Wired.IO Platform benchmark using [Unhinged - https://github.com/MDA2AV/Unhinged] epoll engine.
14+
*
15+
* This test was created purely for benchmark/comparison between .NET solutions.
16+
* It should not be considered EVER as a go-to framework to build any kind of webserver!
17+
* For such purpose please use the main Wired.IO framework [Wired.IO - https://github.com/MDA2AV/Wired.IO].
18+
*
19+
* This benchmarks follows the JsonSerialization and PlainText rules imposed by the TechEmpower team.
20+
*
21+
* The Http parsing by the Unhinged engine is still naive(work in progress), yet it's development will not have any impact
22+
* on these benchmarks results as the extra request parsing overhead is much smaller than the read/send syscalls'.
23+
*/
24+
1125
namespace Platform;
1226

1327
[SkipLocalsInit]
@@ -17,16 +31,30 @@ public static void Main(string[] args)
1731
{
1832
var builder = UnhingedEngine
1933
.CreateBuilder()
20-
.SetNWorkersSolver(() => Environment.ProcessorCount - 2) // Number of working threads, depends on a lot of things
21-
.SetBacklog(16384) // Accept up to 16384 connections
22-
.SetMaxEventsPerWake(512) // Max 512 epoll events per wake (quite overkill)
23-
.SetMaxNumberConnectionsPerWorker(512) // Max 512 connection per thread
2434
.SetPort(8080)
25-
.SetSlabSizes(32 * 1024, 32 * 1024) // 32KB slabs to handle high pipeline depth
35+
36+
37+
// Number of working threads
38+
// Reasoning behind Environment.ProcessorCount / 2
39+
// It's the number of real cpu cores not cpu threads
40+
// This can improve the cache hits on L1/L2 since only one thread
41+
// is running per cpu core.
42+
.SetNWorkersSolver(() => Environment.ProcessorCount/2)
43+
44+
// Accept up to 16384 connections
45+
.SetBacklog(16384)
46+
47+
// Max 512 epoll events per wake (quite overkill)
48+
.SetMaxEventsPerWake(512)
49+
50+
// Max 512 connection per thread
51+
.SetMaxNumberConnectionsPerWorker(512)
52+
53+
// 32KB in and 16KB out slabs to handle 16 pipeline depth
54+
.SetSlabSizes(32 * 1024, 16 * 1024)
2655
.InjectRequestHandler(RequestHandler);
2756

2857
var engine = builder.Build();
29-
3058
engine.Run();
3159
}
3260

0 commit comments

Comments
 (0)