Skip to main content

Load Balance Probe of Azure - Custom Load Balance logic

In today post we will see how we can define our own probe for load balancer. Before going deeper about this topic, let’s make a step back and talk a little about Azure and Load Balancer.
On Azure, we have a load balancer out of the box. We don’t need to pay extra for it or activate it. In the moment when we have more than one instance of a specific role, load balancer will start to work and do his job.
Load balancer use a Load Balancer Probe (we will call Probe) to check the status of an instance. Basically a call is made to each instance every few seconds. If the status of instances is different from Ready (!=HTTP 200 OK) the instances will be marked as ‘ill’.
Using this Probe, Load balancer is able to determine the health status of each instance. When the health status is not OK, all the traffic will be redirected automatically to other instances. By default a call is made every few seconds and check the health of instances. The call use the Guest Agent that is inside each virtual machine (including web and worker roles).
This works very good, but there are times when we want to do more than that. For example if we have a web role, we would like to mark the instance status as ill if we have a failure on our web application (HTTP 500). Because the Probe don’t check the status of IIS (w3wp.exe) process, the load balancer is not aware of this problem.
Another use case could be when we want to mark an instance as ill when the process level is over 90% or the available memory is more than 80%. We can imagine other hundreds of use case also.
To be able to create a custom probe we need to expose a valid endpoint of our instance. This will be used to check the status of our machine. We can add any kind of logic to our endpoint. For example we can add a logic that returns an error code different from 200 when the processor level is over 90% or if we have more 10 requests in parallel that process an image.
Once we created our endpoint we need to transmit this custom configuration to Azure. This is done using .csdef file (Azure Project). In the ServiceEndpoint definition we add LoadBalancerProbe node that can contains the following information:

  • Name – name of the Probe
  • Protocol – the protocol that should be used (in this moment we have support for HTTP or TCP)
  • Uri – the endpoint address that will be used to check the status
  • Port – the port value for request
  • IntervalInSeconds – specify how often the check should be done
  • TimeoutInSeconds – The timeout period of our custom endpoint

In the below example we set the Probe to a custom endpoint:
  <LoadBalancerProbes>
    <LoadBalancerProbe name="FooProbe" protocol="http" intervalInSeconds="30" path="/api/probe" port="80" timeoutInSeconds="60" />
  </LoadBalancerProbes>
Be aware, even if you set HTTP, because Load Balancer is a Layer 3 Load Balancer type, will manage only new connections of TCP type. Because of this requests from the same browser, will be redirected to the same instance if the TCP connection don’t expires (default expiration value of a TCP connection is 4 minutes).
The implementation of api/probe is very simple in our case:
public class ProbeController : ApiController
{
        public IHttpActionResult Index()
        {
            ...
        }
}
If you are using a worker role, don’t forget to expose the endpoint using endpoints node from csdef file.
In this post we saw how we can create a Load Balancer Probe that can be used to mark our instances Good or Note, based on our own logic.

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provided a too