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:
In the below example we set the Probe to a custom endpoint:
The implementation of api/probe is very simple in our case:
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.
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
Post a Comment