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(...

How to audit an Azure Cosmos DB

In this post, we will talk about how we can audit an Azure Cosmos DB database. Before jumping into the problem let us define the business requirement: As an Administrator I want to be able to audit all changes that were done to specific collection inside my Azure Cosmos DB. The requirement is simple, but can be a little tricky to implement fully. First of all when you are using Azure Cosmos DB or any other storage solution there are 99% odds that you’ll have more than one system that writes data to it. This means that you have or not have control on the systems that are doing any create/update/delete operations. Solution 1: Diagnostic Logs Cosmos DB allows us activate diagnostics logs and stream the output a storage account for achieving to other systems like Event Hub or Log Analytics. This would allow us to have information related to who, when, what, response code and how the access operation to our Cosmos DB was done. Beside this there is a field that specifies what was th...

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills)

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills) The idea that moving to the cloud reduces the costs is a common misconception. The cloud infrastructure provides flexibility, scalability, and better CAPEX, but it does not guarantee lower costs without proper optimisation and management of the cloud services and infrastructure. Idle and unused resources, overprovisioning, oversize databases, and unnecessary data transfer can increase running costs. The regional pricing mode, multi-cloud complexity, and cost variety add extra complexity to the cost function. Cloud adoption without a cost governance strategy can result in unexpected expenses. Improper usage, combined with a pay-as-you-go model, can result in a nightmare for business stakeholders who cannot track and manage the monthly costs. Cloud-native services such as AI services, managed databases, and analytics platforms are powerful, provide out-of-the-shelve capabilities, and increase business agility and innovation. H...