Menu

1 / 4

System.Threading.Channels in .NET 10, Measured: The Write Said True and the Item Was Gone

DEV Community: dotnet·Juan Gómez·about 3 hours ago
#yGvYIGD8
#devtodotnet#devto#dev#task#stage
Reading 0:00
15s threshold

System.Threading.Channels in .NET 10, Measured: The Write Said True and the Item Was Gone

When a producer is faster than its consumer, something has to give. The queue between them can grow without limit, the producer can be made to wait, or items can be thrown away. System.Threading.Channels makes you pick one of those, which is exactly what it should do. What surprised me is how two of the choices report it: a bounded channel in a drop mode answers true to the write of an item it has just thrown away.

I measured an unbounded channel and all four modes of a bounded one under the same load on .NET 10, then broke a three-stage pipeline in the middle to see who notices. Short answer: nobody, unless every stage is wired to tell the others.

Every example below is a .NET 10 file-based app: save the block as a .cs file and run it with dotnet run -c Release <file>.cs , with no project file. The numbers come from .NET 10.0.15 on an 8-core laptop.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.