How to find and log slow queries in Entity Framework using the interceptor system

In Entity Framework Core we can log slow running queries using the interceptor system. This is easy and involves two main steps…

Create an interceptor class which inherits from DbCommandInterceptor and implement the ReaderExecuted method.

and

Register the interceptor class from the ConfigureServices method in Startup.cs

How to set the Ratio column style in BenchmarkDotNet results

By default when you output the Ratio column in BenchmarkDotNet using the Baseline = true attribute it is output using the Value approach below. This means that the baseline method will be shown as 1.00 and that other methods will be shown as a relative value to this.

If we wish we can also output the Ratio column using trends or percentages as shown below. To do this we need to tell BenchmarkDotNet the name of the class which contains our configuration and then within that class with need to set the RatioStyle enum…

How to output the Ratio column when using BenchmarkDotNet

If you’re using BenchmarkDotNet and want to see how other methods compare against a baseline method, set the Baseline attribute on your baseline method. Doing this will result in the Ratio column being outputted as shown below…

More info from the Benchmark and Job Baselines page on BenchmarkDotNet.org.

Defer loading of images until a user scrolls to them using the HTML loading = lazy attribute

For your images which are ‘below the fold’ consider using the HTML loading=’lazy’ attribute which will defer loading of images until a user scrolls to them.

In the demo video below the page has 100 cat pictures but we can see from developer tools that they are not requested until a user scrolls to them so there is no wasted bandwidth.

The attribute is supported by most popular Chromium-powered browsers (Chrome, Edge, Opera) and Firefox. Browsers that do not support the loading attribute simply ignore it without side-effects.

Is anyone using this at the moment? It would be ideal to use on ecommerce or catalogue type of sites which are heavy on images where I imagine it could save lots of GBs of bandwidth every month.

More information from Google ->
Browser-level image lazy-loading for the web

What are Proximity Placement Groups and how to create them in the Azure Portal

From an architectural point of view, it’s recommended to place any VMs which need to communicate with each other in the same region and availability zone to lower latency. Note that lower latency is a side effect not a design goal of using AZs.

One further level of latency optimisation possible in Azure is called Proximity Placement Groups.

What are Proximity Placement Groups?

While Availability zones allow resources to be placed in the same group of physical data centers, this still could mean they’re in different data centres perhaps many kilometers apart…

Availability Zones with PPGsProximity Placement Groups assure that resources are placed in the same data centre

Availability Zones with PPGs

By using PPGs absolute physical distance which is one of the main factors impacting network latency between VMs can be reduced.

PPGs can benefit all multi-tiered apps but are ideal in very latency sensitive applications such as those used in banking, trading etc. When combined with accelerated networking sub-millisecond latency times between VMs can be achieved.

The data centre associated with a PPG is allocated when the first VM is added to the group. All subsequent VMs added to the PPG will get added to the same data centre as the first VM. A subsequent request for a different virtual machine SKU may fail since it’s not available in the data centre already selected. For this reason Microsoft recommends adding the most exotic SKU to your PPG first.

Creating Proximity Placement Groups in Azure Portal

Adding PPGs in the Azure portal is easy. Search for ‘proximity placement groups’, visit the default listing page and click new.

All that’s needed is resource group, region and name. Obviously your region must be the same as where your virtual machines are located.

You can create PPGs via ARM templates, the CLI and PowerShell too.

Note that you need to create the PPG first using one of the above approaches before you can place a new or existing VM into it, there is no ability to create a new PPG inline (as you might with resource groups).

When creating a new VM, the PPG section is found near the end of the page on the Advanced tab.

When editing an existing VM the PPG section is found in Settings -> Configuration. Note the virtual machine needs to be stopped/deallocated to amend its PPG config.

Links

Create Windows VM with accelerated networking – Azure PowerShell | Microsoft Docs

0.09 ms latency using Azure Proximity Placement Groups (telstra.com.au)