Developer knowledge network · moderated exchange

مجتمع الكود غير الموثوق به

أبحاث المطورين، مجتمع الهندسة العكسية والترميز

Knowledge indexيعيش
4Categories
919Threads
2.8Kدعامات
Tutorial

Processing High-Throughput Network Streams with System.IO.Pipelines (PipeReader / PipeWriter) [StackOverflow Architecture Guide]

channel_concurrency
Reactive & Pipeline
MEMBER
مندوب: 156
تاريخ الانضمام: Jan 2022
دعامات: 10
شكرًا: 16
2 weeks ago · Aug 8, 2026 1:10 AM
#1

Why System.IO.Pipelines (the engine behind ASP.NET Core Kestrel) beats traditional Stream and byte[] buffers:

  • Memory Management: Automatically manages buffer pooling and zero-copy slicing.
  • Backpressure: PipeWriter pauses upstream producers when downstream consumers are busy.
  • Line/Packet Parsing:
CSHARP
while (true)
{
    ReadResult result = await reader.ReadAsync();
    ReadOnlySequence<byte> buffer = result.Buffer;
    while (TryReadLine(ref buffer, out ReadOnlySequence<byte> line))
    {
        ProcessLine(line);
    }
    reader.AdvanceTo(buffer.Start, buffer.End); // Tells pipeline which bytes were consumed!
    if (result.IsCompleted) break;
}
csharp_async_master
Async & Task Expert
MEMBER
مندوب: 57
تاريخ الانضمام: Mar 2019
دعامات: 18
شكرًا: 40
2 weeks ago · Aug 8, 2026 5:15 AM
#2

System.IO.Pipelines is how Kestrel handles millions of HTTP requests per second with flat memory usage.

dotnet_runtime_architect
.NET Core Specialist
MEMBER
مندوب: 103
تاريخ الانضمام: Apr 2018
دعامات: 40
شكرًا: 24
2 weeks ago · Aug 8, 2026 3:28 PM
#3

The AdvanceTo(consumed, examined) design solves the classic 'incomplete packet' problem cleanly.