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(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

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