English | 한국어
High Performance C# TCP Socket Server Framework — https://www.nuget.org/packages/Dignus.Sockets
Echo servers built on Dignus.Sockets, DotNetty, SuperSocket, and NetCoreServer, driven by the same neutral client on the same machine. The method is described below the results.
- Machine: Intel Core i9-14900K (32 logical processors), 64 GB, Windows 10.0.26300, .NET 10.0.12, Release.
- GC: server GC for the servers, workstation GC for the client. What changes under workstation GC is below.
- Cores: server on logical processors 0–7 (performance cores). Client on 8–15 (performance cores) in single-connection scenarios and on 8–31 otherwise.
- Runs: each run starts a fresh server, warms up for 5 s (not measured) and measures 10 s. 5 rounds with library order rotated. All 50 default runs and 100 other-scenario runs passed byte-for-byte verification and the drain check (no failed runs).
- Machine load: a separate per-process CPU sampler (every 5 s) showed other processes using a median of at most 1 core. During the other-scenario runs there were short periods of 3–12 cores.
- Versions: Dignus.Sockets 2.0.11, DotNetty 0.7.6, SuperSocket.Server 2.1.0, NetCoreServer 8.0.7.
- Raw data: default scenarios in
results/20261106-115458/summary.md, other scenarios inresults/20261106-121523/summary.md; every run inruns.jsonlnext to each.
Messages/s is the median of 5 runs; "range" is the per-run range. When the ranges of two libraries overlap, their order is not established.
Raw echo, 1 connection: NetCoreServer's round-trip benchmark (server echoes received bytes, no framing)
| Dignus.Sockets | SuperSocket | DotNetty | NetCoreServer | |
|---|---|---|---|---|
| msg/s | 9,768,398 | 8,877,758 | 7,900,797 | 8,798,696 |
| Range | 9.69M–9.99M | 8.80M–9.47M | 7.79M–8.01M | 8.66M–8.99M |
| p99 (µs) | 236.7 | 345.5 | 313.5 | 271.9 |
| Server CPU (cores) | 2.15 | 2.75 | 1.14 | 1.07 |
| Messages per server CPU-second | 4,517,501 | 3,295,242 | 6,907,704 | 8,212,711 |
- Order: Dignus.Sockets > SuperSocket and NetCoreServer > DotNetty. SuperSocket and NetCoreServer overlap.
- CPU: Dignus.Sockets and SuperSocket used 2–3 times the CPU of NetCoreServer and DotNetty for the same throughput.
- Write sizes: DotNetty and NetCoreServer answered with the whole window at once (32,000 bytes per client read), Dignus.Sockets and SuperSocket with about 14,600 bytes.
- The single client thread tops out around 10M/s, so this scenario only shows differences below that.
| Dignus.Sockets | SuperSocket | DotNetty | NetCoreServer | |
|---|---|---|---|---|
| msg/s | 17,425,557 | 9,488,404 | 3,453,954 | 577,319 |
| Range | 16.51M–17.88M | 9.20M–9.72M | 3.45M–3.49M | 0.571M–0.581M |
| p50 / p99 (ms) | 0.57 / 0.80 | 0.95 / 3.15 | 0.75 / 19.0 | 6.1 / 57.3 |
| Server CPU (cores) | 7.80 | 7.48 | 2.54 | 7.82 |
| Server alloc (B/msg) | 0.6 | 102.8 | 147.4 | 0.0 |
- Established: no ranges overlap.
- NetCoreServer hands each response to
SendAsync, which starts a socket send right away when none is in progress, so every response goes out as its own small segment (270 bytes per client read, against about 3,200 bytes from the other three). The server used all 8 cores. - DotNetty used 2.5 cores and spent the rest waiting. DotNetty 0.7.6 passes pending responses to .NET's
Socket.Send(IList<ArraySegment<byte>>)as one segment per message, and that method pins and unpins every segment with aGCHandle. The event-loop threads (16 by default) contend on the GC handle table. A diagnostic copy that gathers the responses of a read into one buffer, so each send has one segment, reached 11.7M against 0.65M for the original under workstation GC (one run each; not used in the benchmark server).
| Raw echo, 1 conn. | Message echo, 1 conn. | |
|---|---|---|
| msg/s | 9,420,599 | 8,520,376 |
| Range | 9.31M–9.46M | 8.20M–8.66M |
The client used 0.91–0.95 of a core, so both may be limited by the client.
The scenarios in Workloads that are not in the default run (selected with --scenarios). Each cell is the median msg/s with the per-run range (M) in parentheses.
| Scenario | Dignus.Sockets | SuperSocket | DotNetty | NetCoreServer |
|---|---|---|---|---|
| Raw echo, 100 conn. | 32.42M (31.14–33.37) | 28.98M (28.82–29.36) | 27.14M (25.40–31.72) | 25.76M (24.30–29.52) |
| Message echo, 1 conn. | 9.75M (9.63–9.87) | 4.17M (3.93–4.37) | 4.57M (4.10–4.73) | 0.118M (0.113–0.127) |
| Message echo, 100 conn., 100 B | 9.03M (8.94–9.25) | 6.82M (6.68–6.89) | 3.84M (3.71–3.93) | 0.568M (0.553–0.569) |
| Message echo, 100 conn. + 100 joining under load | 16.36M (15.89–17.47) | 9.51M (9.37–9.80) | 3.88M (3.39–4.15) | 0.577M (0.563–0.583) |
| JSON, 1,000 conn. | 0.206M (0.113–0.214) | 0.172M (0.144–0.222) | 0.180M (0.143–0.242) | 0.211M (0.135–0.230) |
- Order:
- Raw echo with 100 connections: Dignus.Sockets is above SuperSocket and NetCoreServer; the rest overlap.
- Message echo with 1 connection: Dignus.Sockets is highest and NetCoreServer lowest; SuperSocket and DotNetty overlap.
- 100-byte and joining scenarios: Dignus.Sockets > SuperSocket > DotNetty > NetCoreServer, all established.
- JSON: all four overlap.
- Joining connections: all four libraries answered all 100 joining connections. Median time to first response: SuperSocket 1.7 ms, Dignus.Sockets 1.9 ms, DotNetty 4.0 ms, NetCoreServer 66 ms.
- Client limit: in 1-connection message echo, the client used 0.87–0.91 of a core in the Dignus.Sockets, SuperSocket and NetCoreServer runs.
The same default scenarios measured with workstation GC (results/20261105-160829, Windows 10.0.26200) differed much only for DotNetty in 100-connection message echo: 0.77M (0.85 cores, p50 8.8 ms). Workstation GC has a single GC handle table, so the contention above is worse. In that scenario the other three were within ±10% and in the same order (Dignus.Sockets 16.48M, SuperSocket 10.12M, NetCoreServer 0.57M). Reproduce with --gc workstation.
This benchmark is maintained by the author of Dignus.Sockets. To keep the comparison fair, the other servers follow their libraries' own examples, every setting that differs from a library default is listed below, and all raw data is published with the results. Maintainers and users of the other libraries are welcome to open pull requests that improve their server code.
Wire format for every server and the client: [size: int32 LE][protocol: int32 LE][body], where size counts the bytes after the size field.
| Scenario | Default | Connections | Messages in flight per connection | Message | What it shows |
|---|---|---|---|---|---|
stream-c1-w1000-s32 |
yes | 1 | 1,000 | 32 B | NetCoreServer round-trip benchmark, 1 client |
stream-c100-w1000-s32 |
100 | 1,000 | 32 B | NetCoreServer round-trip benchmark, 100 clients | |
frame-c1-w1000-s32 |
1 | 1,000 | 32 B | Per-message processing on one pipelined connection | |
frame-c100-w100-s32 |
yes | 100 | 100 | 32 B | Per-message processing across connections |
frame-c100-w100-s100 |
100 | 100 | 100 B | Same, with frames that are split across reads | |
frame-c100-w100-s32-join100 |
100 + 100 joining | 100 | 32 B | New connections arriving while the server is under load | |
json-c1000-w1 |
1,000 | 1 | 42 B | Many connections, one request at a time, small JSON processing per message | |
stream-c1-w1000-s32-tls |
yes | 1 | 1,000 | 32 B | Raw echo over TLS (Dignus only; no other TLS server is implemented) |
frame-c1-w1000-s32-tls |
yes | 1 | 1,000 | 32 B | Message echo over TLS (Dignus only) |
In scenario names, stream is raw echo and frame is message echo.
- Raw echo (
stream-…) follows NetCoreServer's round-trip benchmark. The server sends back whatever it received, as it is, without cutting frames, with one send per receive. The NetCoreServer server in this mode is NetCoreServer's ownTcpEchoServersession. The scenario measures the transport path (receive, send, buffering) and does no per-message work on the server. - Message echo (
frame-…): the server cuts one frame at a time with its library's framing API and sends that frame back unchanged, one send call per frame. 32 bytes divides the servers' read sizes (4 KB, 8 KB), so frames rarely straddle two reads. 100 bytes does not, so the partial-frame path of every server is exercised. - Joining connections (
-join<n>): while the measured load runs, n more connections are opened one at a time and start the same load immediately, with no start barrier. The summary reports how many were served (first response within 5 s of the connection attempt), connection failures, connections that got no response, and the time to the first response. These are results, not run failures. Messages/s and the per-message server figures (CPU, allocation) include the joining connections' round trips, because the server's CPU and allocation include them. Latency and Conn min/max cover the initial connections. - JSON echo: the server deserializes the body (
{"Message":"..."}) toEchoMessagewith System.Text.Json, serializes it again, and sends a new packet.- 1,000 connections, not 5,000: with 5,000 connections on one Windows machine over loopback, each run fell into one of two states, whichever library was serving: about 150K–235K messages/s, or about 37K–60K with p99 latency around 250–380 ms. The order of the libraries followed which of their runs fell into the slow state. With 1,000 connections no run collapsed (p99 8–39 ms). Giving the client fewer cores made the slow periods shorter but did not remove them; the cause was not identified.
json-c5000-w1can still be run with--scenarios.
- 1,000 connections, not 5,000: with 5,000 connections on one Windows machine over loopback, each run fell into one of two states, whichever library was serving: about 150K–235K messages/s, or about 37K–60K with p99 latency around 250–380 ms. The order of the libraries followed which of their runs fell into the slow state. With 1,000 connections no run collapsed (p99 8–39 ms). Giving the client fewer cores made the slow periods shorter but did not remove them; the cause was not identified.
- Scenario names are parsed, so other shapes can be run:
{stream|frame|json}-c<connections>-w<window>[-s<bytes>][-tls][-join<n>].
The raw echo scenarios keep NetCoreServer's shape (clients, messages in flight, message size, one message sent per message received, data and message throughput). Their summary also prints NetCoreServer's report format. These parts differ:
NetCoreServer TcpEchoClient |
This benchmark | |
|---|---|---|
| Client | NetCoreServer TcpClient |
Neutral client (plain sockets) |
| Timing | From before connecting to the last receive | Warmup excluded; fixed measured window |
| "Message latency" | Total time / messages | Reported the same way in the NetCoreServer-format table, plus measured round-trip percentiles |
| Message content | Zero bytes, not checked | Connection id + sequence number, every byte checked |
| Nagle | Left on (OptionNoDelay commented out) |
NoDelay on for every server and the client |
| Repeats | One run | 5 rounds, median and range |
| Library | Package | Framing | Send | Changed from library defaults |
|---|---|---|---|---|
| Dignus.Sockets | Dignus.Sockets 2.0.11 | Message echo: PacketProcessor, one frame per TakeReceivedPacket. Raw echo: PacketProcessor takes every received byte. JSON: SessionlessPacketProcessor + ProtocolHandlerMapper |
ISession.SendAsync per message (raw echo: per receive) |
backlog 1024, NoDelay (already the default) |
| DotNetty | DotNetty.Transport / Codecs 0.7.6 | Message and JSON echo: LengthFieldBasedFrameDecoder. Raw echo: no decoder |
WriteAsync per message (raw echo: per receive), Flush in ChannelReadComplete (DotNetty's echo example pattern) |
1 boss event loop, backlog 1024 (NoDelay is already the default) |
| SuperSocket | SuperSocket.Server 2.1.0 | Message and JSON echo: FixedHeaderPipelineFilter, data copied in DecodePackage. Raw echo: Filter copies every received byte |
await IAppSession.SendAsync per message (raw echo: per receive) |
backlog 1024, NoDelay; a package error handler that counts errors and closes the session, as SuperSocket's default does |
| NetCoreServer | NetCoreServer 8.0.7 | No framing layer in the library. Raw echo: none (TcpEchoServer). Message and JSON echo: frames cut in OnReceived |
TcpSession.SendAsync per message (raw echo: per receive, as in TcpEchoServer) |
NoDelay; OptionReuseAddress as in TcpEchoServer (backlog default is already 1024) |
| Dignus.Sockets (TLS) | Dignus.Sockets 2.0.11 | same as plain TCP message and raw echo, on TlsServerBase |
same as plain TCP | backlog 1024, NoDelay; self-signed server.pfx |
Notes:
- Worker thread and event-loop counts are library defaults. They follow
Environment.ProcessorCount, which the runner sets to the server's core count. - SuperSocket copies the frame (or decodes the JSON string) inside
DecodePackage.SuperSocketService.HandleSessionreads the next package before awaiting the previous handler, so a handler must not keep the receive buffer. - How responses reach the socket. No server collects responses in application code; each response is handed to the library as it is produced. What happens next is each library's own behavior:
- Dignus.Sockets:
SendAsyncappends to the session's send buffer and starts the socket send on the thread pool, so responses added in the meantime go out together. - NetCoreServer:
SendAsyncappends to the session's send buffer. If no socket send is in progress, it starts one immediately on the calling thread. On loopback such sends usually complete at once, so in practice each response becomes its own socket send. - SuperSocket:
SendAsyncwrites to the connection's output pipe and flushes it. - DotNetty separates writing from flushing by design. Its official echo example writes per message and flushes once per read batch, which is what is used here. Flushing every message is published as a variant (below).
- Dignus.Sockets:
- NetCoreServer message and JSON echo: the session cuts frames in
OnReceived. A frame split across receives is kept in a buffer that is allocated only when that happens. - DotNetty leak detection stays at DotNetty's default (
Simple): about one buffer in 128 is tracked with a captured stack trace. Turning it off is published as a variant. - SuperSocket socket buffers: SuperSocket sets the kernel buffers (
SO_RCVBUF,SO_SNDBUF) of every accepted socket to itsReceiveBufferSizeandSendBufferSize, 4096 by default. The other servers leave the kernel buffers at the OS default, and their "receive/send buffer" settings are user-space buffers. Leaving SuperSocket's kernel buffers at the OS default is published as a variant. - Error counters: Dignus.Sockets counts invalid frames and failed sends, DotNetty counts pipeline exceptions, SuperSocket counts package handling errors, and NetCoreServer counts socket errors and failed sends. DotNetty write failures are not counted separately; a response lost that way fails the run on the client side.
--with-variants adds these to the libraries. Each changes one library default, to show how much that default matters:
| Variant | Change |
|---|---|
dotnetty@flush=message |
WriteAndFlushAsync per message instead of one flush per read batch |
dotnetty@leak-detection=disabled |
ResourceLeakDetector.Level = Disabled |
supersocket@socket-buffers=os |
kernel socket buffers left at the OS default (read size unchanged, 4096) |
Any server option can be tried the same way, for example --libraries dignus,dignus@receive-buffer=65536.
- Each server's settings are printed at startup and stored with every run.
BenchClient uses only System.Net.Sockets (and SslStream for TLS). It contains no server library code.
- Start barrier: all connections are opened first. Each one then completes one round trip before any load starts, so the server has accepted and is serving every connection when the load begins. Accepting connections under load is covered separately by the join scenario.
- Closed loop: each connection keeps
windowrequests in flight. When responses arrive, the same number of new requests is sent in one write. - Verification: every request carries its connection id and a sequence number, and every response is compared byte for byte with what was expected. A duplicated, reordered, or corrupted response fails the run.
- Drain: after the measured window the client stops sending and waits up to 5 s for every outstanding response. A response that never arrives fails the run.
- Close: after the drain the client resets its connections (
Socket.Close(0), RST) instead of closing them gracefully. A graceful close leaves each socket in TIME_WAIT, two minutes by default on Windows. After a 5000-connection run, about 5,000 TIME_WAIT sockets stayed for those two minutes, and single-connection raw echo runs in that window repeatedly dropped to about 1–2M messages/s; they stopped dropping as soon as the TIME_WAIT sockets expired. The server's counters are read before the connections are closed. - Latency: the round-trip time of every request is measured with
Stopwatch. Results go into a log-linear histogram with under 1.6% relative error, reported as p50, p90, p99, p99.9, and maximum. With a window above 1, this includes time queued behind earlier requests. - Fairness: messages are counted per connection. A connection that completes nothing during measurement fails the run. The slowest one-second interval is reported, so stalls are visible.
- Socket calls: the client records its reads and writes during the window. "Client bytes per read" shows how the server segments its responses; small values mean many small segments.
- Threading: one blocking thread per connection up to 64 connections, async I/O above that.
- Core pinning: the server and the client are pinned to separate cores. By default the server gets the first half of the logical processors and the client gets the second half.
DOTNET_PROCESSOR_COUNTis set to each side's core count. - One run:
- A fresh server process starts.
- The client connects and runs a 5 s warmup, which is not measured.
- 10 s are measured.
- At the start and end of the measured window, the runner reads the server's CPU time and asks the server for GC counters over stdin (
stats).
- Repeats: 5 rounds. Library order rotates every round, so no library always runs first or last. With the default scenarios, one round is 10 runs (4 libraries × 2 scenarios + 2 Dignus TLS runs), about 3 minutes, so 5 rounds take about 15 minutes.
--scenarios allruns every scenario in the table (30 runs per round, about 9 minutes).--with-variantsadds 6 runs per round with the default scenarios. - Reporting: medians of successful runs, plus the per-run range of messages/s. When the ranges of any two libraries overlap, the summary says that their order is not established.
- Failed runs: a run fails if the client reports any error (including responses lost at the drain), if a server error counter is non-zero, or if the server exits. Failed runs are listed and excluded from the medians.
- Output files, in
results/<timestamp>/:environment.json: CPU, memory, OS, runtime, git commit, whether the working tree had uncommitted changes (untracked files included), a SHA-256 of the benchmark sources, and settings.runs.jsonl: one JSON object per run, with server settings, client result, server CPU and GC snapshots.summary.md: the tables.runner.log: all process output.
- Messages/s: completed round trips per second during the measured window. Lowest 1 s: the slowest one-second interval in the window.
- Server CPU (cores): user plus kernel CPU time of the server process during the window, divided by the window length. Messages per server CPU-second is completed messages divided by that CPU time. Kernel and user time are stored separately in
runs.jsonl. - Server alloc (B/msg): the change in
GC.GetTotalAllocatedBytesin the server, divided by messages. - GC:
- Generation counts come from
GC.CollectionCount(0/1/2). These counters overlap and must not be added together. - Pause time comes from
GC.GetTotalPauseDuration().
- Generation counts come from
- Server peak memory: the server's peak working set, which includes the warmup.
- Client CPU (cores): the client process's own CPU time during the window. The summary flags runs where the client used 85% or more of the cores it can use, because the client may then be the limit.
Requires the .NET 10 SDK.
dotnet build ServerPerformanceBenchmark.slnx -c Release
dotnet BenchRunner/bin/Release/net10.0/BenchRunner.dll| Option | Default | |
|---|---|---|
--rounds |
5 | Rounds; every (scenario, library) pair runs once per round |
--warmup / --duration |
5 / 10 | Seconds |
--scenarios |
the four marked default above | Comma-separated scenario names, or all |
--libraries |
dignus,dotnetty,supersocket,netcoreserver,dignus-tls |
Pairs a library does not support are skipped. name@key=value runs a variant |
--with-variants |
off | Adds the published variants |
--server-cores / --client-cores |
first half / second half | e.g. 0-7 and 8-31 |
--single-client-cores |
same as --client-cores |
Client cores for single-connection scenarios, e.g. 8-15 |
--gc |
server |
The server's GC mode: server sets DOTNET_gcServer=1 for the server only, workstation sets 0. The client always uses workstation GC |
--out |
results/<timestamp> |
Recalculate a summary from existing data with BenchRunner --summarize results/<timestamp>.
Before measuring:
- Idle machine: close other CPU-heavy programs. Trial runs made while another process was using about 8 cores differed by more than an order of magnitude between runs of the same configuration.
- Hybrid CPUs (performance and efficiency cores): choose
--server-coresand--client-coresexplicitly and state the choice with the results. With the default split on an i9-14900K, for example, the client runs on efficiency cores only.- A single-connection client is one thread. If its cores mix both kinds, each run lands on one kind by chance and that decides the result more than the library does. On an i9-14900K with the client on
8-31, the same Dignus raw echo run gave about 5.5M or 9.9M messages/s depending on the run; with the client on8-15(performance cores only) every library ran faster and steadier. Give--single-client-corescores of one kind.
- A single-connection client is one thread. If its cores mix both kinds, each run lands on one kind by chance and that decides the result more than the library does. On an i9-14900K with the client on
- Unreleased Dignus builds: copy
Dignus.dllandDignus.Sockets.dllinto aDlls/folder at the repository root and build with-p:UseLocalDignus=trueto use them instead of the NuGet package. The library version recorded with each run shows which one was used.
- Shared machine: the client and server run on the same machine over loopback, so they share the memory system and the operating system's network stack.
- Kernel cost at window 1: with one request in flight per connection, every message is its own TCP segment and the kernel network stack dominates CPU time. In trial runs on Windows, most CPU time on both sides was kernel time. That scenario measures the operating system and the library together.
- Single-connection scenarios: the client loop is one thread, so the client can be the limit. The summary flags it.
- Refill rule: the client sends as many new requests as responses it just received, in one write. When a server answers in small segments, the client's next writes are small too, which can keep both sides exchanging small segments. "Client bytes per read" shows when this happens.
- Thread-pool spinning: Dignus.Sockets, SuperSocket and NetCoreServer run on the .NET thread pool, whose workers spin briefly before sleeping. At partial load this adds CPU time that is not work, which lowers their messages per CPU-second. DotNetty's event loops spin less.
- CPU time on Windows: process CPU times come from
GetProcessTimes, which is sampled at the clock tick. Busy processes are measured well, but mostly idle processes can be under-counted. - Coverage: the results describe these configurations on one machine, not universal rankings.
| Folder | |
|---|---|
BenchRunner |
Starts the servers and the client, records runs, writes the summary |
BenchClient |
Neutral load generator |
Shared |
Wire format, argument parsing, server lifecycle (READY / stats / exit) |
DignusSocketServer, DignusTlsServer, DotNettyServer, SuperSocket, NetCoreServerServer |
Servers under test |
results/<timestamp> |
Published result sets |