Roundup #62: ConfigureAwait, System.Threading.Channels, New Executive Director of .NET Foundation, Event Driven Collaboration, What You Need to Know About Open Source

Here are the things that caught my eye recently in .NET.  I’d love to hear what you found most interesting this week.  Let me know in the comments or on Twitter.

ConfigureAwait FAQ

.NET added async/await to the languages and libraries over seven years ago. In that time, it’s caught on like wildfire, not only across the .NET ecosystem, but also being replicated in a myriad of other languages and frameworks. It’s also seen a ton of improvements in .NET, in terms of additional language constructs that utilize asynchrony, APIs offering async support, and fundamental improvements in the infrastructure that makes async/await tick (in particular performance and diagnostic-enabling improvements in .NET Core).

However, one aspect of async/await that continues to draw questions is ConfigureAwait. In this post, I hope to answer many of them. I intend for this post to be both readable from start to finish as well as being a list of Frequently Asked Questions (FAQ) that can be used as future reference.

To really understand ConfigureAwait, we need to start a bit earlier…

Link: https://devblogs.microsoft.com/dotnet/configureawait-faq/

An Introduction to System.Threading.Channels

“Producer/consumer” problems are everywhere, in all facets of our lives. A line cook at a fast food restaurant, slicing tomatoes that are handed off to another cook to assemble a burger, which is handed off to a register worker to fulfill your order, which you happily gobble down. Postal drivers delivering mail all along their routes, and you either seeing a truck arrive and going out to the mailbox to retrieve your deliveries or just checking later in the day when you get home from work. An airline employee offloading suitcases from a cargo hold of a jetliner, placing them onto a conveyer belt, where they’re shuttled down to another employee who transfers bags to a van and drives them to yet another conveyer that will take them to you. And a happy engaged couple preparing to send out invites to their wedding, with one partner addressing an envelope and handing it off to the other who stuffs and licks it.

Link; https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels/

Welcoming Oren Novotny as the new Executive Director of .NET Foundation

I started as .NET Foundation Executive Director in February 2017, and a lot has happened over the past nearly three years. We’ve added dozens of high quality projects and added a lot of services to support them, like automated code signing and releases. We launched a worldwide Meetup program that includes over a quarter of a million members, and supported them with hundreds of local events in our .NET Conf Local series. We’ve also ushered in substantial changes, literally years in the making, to open up membership, run an election for the board’s first elected directors, introduce a corporate sponsorship program, and lay the groundwork for the .NET Foundation to grow into its next stage. 

Link: https://www.dotnetfoundation.org/blog/2019/12/16/welcoming-oren-novotny-as-the-new-executive-director-of-net-foundation-

Event Driven Collaboration – Ian Cooper

When we move from a monolith to microservices we abandon integrating via a shared database, as each service must own its own data to allow them it to be autonomous. But now we have a new problem, our data is distributed. What happens if I need one service needs to talk to another about a shared concept such as a product, a hotel room, or an order? Does every service need to have a list of all our users? Who knows what users have permissions to the entities within the micro service? What happens if my REST endpoint needs to include data from a graph that includes other services to make it responsive? And I am not breaking the boundary of my service when all of this data leaves my service boundary in response to a request?

Naive request-based solutions result in chatty calls as each service engages with multiple other services to fulfil a request, or in large message payloads as services add all the data required to process a message to each message. Neither scale well.

In 2005, Pat Helland wrote a paper ‘Data on the Inside vs. Data on the Outside’ which answers the question by distinguishing between data a service owns and reference data that it can use. Martin Fowler named the resulting architectural style; Event Driven Collaboration. This style is significant because it shifts the pattern from request to receiver-driven flow control.

In this presentation we will explain how events help us integrate our service architectures. We’ll provide examples in C#, Python and Go as well as using RMQ and Kafka.

Link: https://www.youtube.com/watch?v=PreAnSofAsA

What You Need to Know About Open Source – Trust Me, I’m a Lawyer – Jeff Strauss

eff is a software developer, an entrepreneur, and an attorney. As a consultant at WWT Asynchrony Labs, with unique experiences that combine technology and law, he maintains a passion for solving problems with inspired solutions, improving life through technology. A dedicated member of the developer community, Jeff travels internationally to speak on both technical and business-oriented topics. He is a Microsoft MVP and enjoys serving on the board of directors for the Kansas City Developer Conference.

Link: https://www.youtube.com/watch?v=k6kpS7q869Y

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Roundup #59: IHostingEnvironment vs IHostEnvironment, Async demystified, Pulumi, Memory management and GC in ASP.NET Core

Here are the things that caught my eye recently in .NET.  I’d love to hear what you found most interesting this week.  Let me know in the comments or on Twitter.

IHostingEnvironment vs IHostEnvironment – obsolete types in .NET Core 3.0

In this post I describe the differences between various ASP.NET Core types that have been marked as obsolete in .NET Core 3.0. I describe why things have changed, where the replacement types are, and when you should use them.

Link: https://andrewlock.net/ihostingenvironment-vs-ihost-environment-obsolete-types-in-net-core-3/

Async demystified – Karel Zikmund

Do you struggle to understand async/await in C#? How it works and why? I did. So I asked the best – the author of async, Stephen Toub. This talk is summary of the most interesting insights from him that helped me and my colleagues on CoreFX team to finally truly understand the magic behind async/await.

The talk will cover: History and evolution of asynchronous programming patterns in C# and their problems. Leading to async/await and demonstrating the “why” behind its design choices.

Touch on the “how” it works behind the scenes.

Reasons for customizing and hyper-optimizing async for high-performance areas (like Networking stack).

Touch on related building block – ThreadPool.

Hands on sync-over-async pattern and associated problems. Workarounds in your code if you hit it. Potential solutions in future .NET versions.

Link: https://www.youtube.com/watch?v=TgUYcZV-foM

Pulumi 💜 .NET Core

Today we are excited to announce the Preview of .NET Core support for all of your modern infrastructure as code needs. This means you can create, deploy, and manage your infrastructure, on any cloud, using your favorite .NET language, including C#, F#, and VB.NET.

Link: https://www.pulumi.com/blog/pulumi-dotnet-core/

Memory management and garbage collection (GC) in ASP.NET Core

Memory management is complex, even in a managed framework like .NET. Analyzing and understanding memory issues can be challenging. This article:

Was motivated by many memory leak and GC not working issues. Most of these issues were caused by not understanding how memory consumption works in .NET Core, or not understanding how it’s measured.

Demonstrates problematic memory use, and suggests alternative approaches.

Link: https://docs.microsoft.com/en-us/aspnet/core/performance/memory?view=aspnetcore-3.0

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Orleans Health Checks using ASP.NET Core

Orleans Health Checks

One of the nicest things with the introduction of the Generic Host in Orleans v3.0 is that it allows you to run Orleans side by side with ASP.NET Core. One of the main benefits that I could think of is creating Orleans health checks using ASP.NET Core Health Checks.

Co-Hosting

Since Orleans 3.0, there is now support for the GenericHost via extensions on IHostBuilder, this allows you to run multiple services within the same process all sharing things such as logging, services, configuration, etc.

In a recent blog post, I covered how you can co-host Orleans and ASP.NET Core. This post is an extension of that. If you have not read that already, go take a look first.

ASP.NET Core Health Checks

The reason for wanting health checks for services like an Orleans Silo are varied. One primary use case is when running a silo that is hosted under some type of container orchestration, such as Kubernetes, AWS ECS, etc.

These orchestrators generally provide a mechanism to determine if your service is healthy or unhealthy. If unhealthy, the will create new instances based on your configuration.

ASP.NET Core has a middleware that simplifies providing such health status. I’ve blogged about creating ASP.NET Core Health Checks over on the Telerik Blog.

Orleans Health Checks

In order to verify that a local silo is healthy, we are going to use a stateless grain. The reason being, stateless grains are always executed locally.

Requests made to Stateless Worker grains are always executed locally, that is on the same silo where the request originated, either made by a grain running on the silo or received by the silo’s client gateway. Hence, calls to Stateless Worker grains from other grains or from client gateways never incur a remote message.

Our grain isn’t really doing anything, and it doesn’t need to. I’ve made it return a bool however, it could just return a Task. Returning a bool might be useful if you plan on doing any other check within the grain, such as maybe verify connections to db, etc.

Next, we’ll create our actual ASP.NET Core Health Check by implementing the IHealthCheck.

All our implementation is going to do is get the IHealthCheckGrain. If anything fails, we’ll return Unhealthy, otherwise its all good so we’ll return Healthy.

As you can see, I also added an extension method off of IHealthChecksBuilder just to simplify registering our new health check.

Finally, to wire up our new health check, we need to add AddHealthChecks and AddOrleansHealthCheck to our ConfigureServices. As well we need to call UseHealthChecks in the Configure method.

Results

Now if you browse or make an HTTP call to the /health endpoint, you get a 200 OK with Healthy if the local silo is running.

Related Links

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.