David Fowler tweeted: Coding challenge for you in any language. I want to see different ways of expressing this computation: The challenge was, of course, expressed in C# and what luck — that was my chosen implementation language! Before I…
Let’s do DHCP: sockets
After our foray into DHCP options, we are ready for the last piece of the puzzle — actually sending and receiving data on a socket. First, we need to encode the high performance receive pattern. I’ve decided on an async…
High performance datagramming: concurrency?
We’ve been looking at some tips and tricks for achieving high performance in a skeletal datagram server. And yet, the implementation so far is single threaded. This is fine if strict packet ordering must be maintained. But we’re talking about…
High performance datagramming: heap?
Last time, we looked at an implementation of a datagram server with and without channels. The non-channel solution ultimately won out in terms of performance. But that’s not all we can do to squeeze every ounce of throughput from this…
High performance datagramming: channels?
You may have heard of System.IO.Pipelines, a set of classes to aid in writing high performance streaming server code. But what about datagram scenarios, e.g. using UDP? That would seem like a job for System.Threading.Channels. Let’s try it and do…
Find the issue: long requests
In the previous post, I discussed a few design changes to a sample Web API controller to fix up the parameters. Here is where we ended up: Of course, we’re not done yet. I ask again: can you find the…
Async minutiae: EndOfStream
Consider the following method to read all text of a file asynchronously. Do you see any issues? The code is perfectly functional and produces the correct result. There are no obvious performance issues (other than perhaps some tuning of the…
Fill in the blanks: an async exercise
A Task-based async operation can either complete synchronously (i.e. return a completed Task right away) or asynchronously (the more common case). Given two sequentially awaited operations, there can thus be four possible behavior combinations: Task 1 Task 2 sync sync…
Async recipes: after first (matching) task, cancel rest
When it comes to the Task-based Asynchronous Pattern, there are easy patterns to run tasks sequentially (await in a loop) and all in parallel (add to list, await WhenAll). Things get slightly more complicated when the execution model doesn’t fit…
Cancellation confusion and Task.Run
Code that heavily relies on Task.Run tends to have issues. In my experience, this is a clear sign that the asynchronous model within the codebase is spotty at best. Indeed, a “really async” design would not generally rely on Task.Run…