Unbounded .NET channels can silently consume 188 MB when consumers lag behind producers
A developer benchmarked System.Threading.Channels in .NET by running 100,000 work items with a producer faster than its consumer, finding that the default unbounded channel accumulated 188 MB of heap memory before draining. Switching to a bounded channel with a capacity of 1,000 and FullMode.Wait kept peak memory at just 19 MB by making the producer await consumer availability. Crucially, total processing time was nearly identical — around 2.25–2.57 seconds — meaning backpressure shifted waiting from heap to producer without hurting throughput. A third mode, DropOldest, completed in just 80 milliseconds but silently discarded 97% of work items, making an ItemDropped callback essential for any data that must not be lost. The author concludes that unbounded channels offer convenience but hide queue buildup, while bounded channels force explicit decisions about backpressure, dropping, or rejection that are better surfaced early.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in