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:
    <LoadBalancerProbe name="FooProbe" protocol="http" intervalInSeconds="30" path="/api/probe" port="80" timeoutInSeconds="60" />
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.


Popular posts from this blog

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 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.51EF 6.0.2VS2013
It seems that there …

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

Fundamental Books of a Software Engineer (version 2018)

More then six years ago I wrote a blog post about fundamental books that any software engineer (developer) should read. Now it is an excellent time to update this list with new entries.

There are 5 different categories of books, that represent the recommended path. For example, you start with Coding books, after that, you read books about Programming, Design and so on.
There are some books about C++ that I recommend not because you shall know C++, only because the concepts that you can learn from it.


Writing solid codeCode completeProgramming Pearls, more programming pearls(recommended)[NEW] Introduction to Algorithms


Refactoring (M. Fowler)Pragmatic ProgrammerClean code[NEW] Software Engineering: A Practitioner's Approach[NEW] The Mythical Man-Month[NEW] The Art of Computer Programming


Applying UML and Patterns (GRASP patterns)C++ coding standards (Sutter, Alexandrescu)The C++ programming language (Stroustrup, Part IV)Object-oriented programming (Peter Coad)P…