LoadBalancerServlet
The LoadBalancerServlet can be used to activate load balancing between two or more Servlets (usually BackendConnectorServlets).
ch::nevis::nevisproxy::servlet::loadbalancer::LoadBalancerServlet
libLoadBalanceServlets.so.1
BC.Tracer.DebugProfile.NPLoadBalance
Configuration
Servlets
Type: comma-sepratated list of servlet names
Usage Constraints: required
Define the servlets over which load balancing has to be done.
RetryTimeout
Type: integer
Unit: seconds
Usage Constraints: required
Timeout after which a connection to a servlet which was down should be retried again.
Algorithm
Type: enum
Possible values: RoundRobin, Failover
Default: RoundRobin
The load balancing algorithm to use.
RoundRobin: an incoming request will use the next servlet used of the previous request and so on. Servlets which are down will be skipped until they come available again.
Failover: always the same servlet will be used for all requests, until it goes down. In that case all requests will switch to the next setvlet until this one goes down again and so on.
IsAliveURI
Type: string
Usage Constraints: required, optional
If an IsAliveUri is set, then the LoadBalancerServlet calls this URI when the backend is down. The URI is called all RetryTimeout seconds until the backend returns a status code configured in IsAliveURI.StatusCodes. Once the backend is up, the URI is not called any more, except when the backend is marked down again after a normal request.
IsAliveURI.StatusCodes
Type: comma separated list of numbers
Usage Constraints: optional
Default: 200
If the IsAliveURI is triggered, then a backend will be marked as up if one of the configured IsAliveURI.StatusCodes is returned.
IsAliveURI.EnablePing
Type: boolean
Usage Constraints: optional
Default: false
The configured IsAliveURI will be called after each RetryTimeout seconds. If none of the configured IsAliveURI.StatusCodes is returned, then the backend will be considered as down (independently of the configured FailoverThresholdCount) otherwise it will be considered as up and running.
FailoverThresholdCount
Type: integer
Usage Constraints: optional, advanced
The number of requests that needs to fail before a servlet is considered defective. Increase this to prevent a failover if an otherwise healthy servlet occasionally fails to satisfy isolated requests.
The failure counters are maintained independently per servlet.
Until the failure counter reaches the configured threshold, the servlet continues to be considered available.
FailoverThresholdCount.LifeTime
Type: integer
Unit: seconds
Range: min: 1
Usage Constraints: required if a FailoverThresholdCount is set
The validity period of the failed request counter. Once the configured time has passed since the last failed request to the servlet, the counter is reset to zero.
Examples
Round robin distribution
In this example the Servlets Backend1 and Backend2 or served in a round robin way for each incoming request. Both Servlets can be either a Http[s]ConnectorServlet (with just one InetAddress configured) or a BackendConnectorServlet.
<servlet>
<servlet-name>LoadBalancerServlet</servlet-name>
<servlet-class>ch::nevis::nevisproxy::servlet::loadbalancer::LoadBalancerServlet</servlet-class>
<init-param>
<param-name>Servlets</param-name>
<param-value>Backend1, Backend2</param-value>
</init-param>
<init-param>
<param-name>RetryTimeout</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>Algorithm</param-name>
<param-value>RoundRobin</param-value>
</init-param>
</servlet>
Failover distribution over two lines
Assume you have two line with to backends. The first line has the Servlets called Backend1 and Backend2, the second line the Servlets called FallBack1 and Fallback2.
This four Servlets can be either a Http[s]ConnectorServlet (with just one InetAddress configured) or a BackendConnectorServlet.
As long as Backend1 and Backend2 are up, only those will be served. As soon as they go down (for example for maintenance) it switches to FallBack1 and Fallback2.
<servlet>
<servlet-name>LoadBalancerServlet_Line1</servlet-name>
<servlet-class>ch::nevis::nevisproxy::servlet::loadbalancer::LoadBalancerServlet</servlet-class>
<init-param>
<param-name>Servlets</param-name>
<param-value>Backend1, Backend2</param-value>
</init-param>
<init-param>
<param-name>RetryTimeout</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>Algorithm</param-name>
<param-value>RoundRobin</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>LoadBalancerServlet_Line2</servlet-name>
<servlet-class>ch::nevis::nevisproxy::servlet::loadbalancer::LoadBalancerServlet</servlet-class>
<init-param>
<param-name>Servlets</param-name>
<param-value>FallBack1, FallBack2</param-value>
</init-param>
<init-param>
<param-name>RetryTimeout</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>Algorithm</param-name>
<param-value>RoundRobin</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>LoadBalancerServlet</servlet-name>
<servlet-class>ch::nevis::nevisproxy::servlet::loadbalancer::LoadBalancerServlet</servlet-class>
<init-param>
<param-name>Servlets</param-name>
<param-value>LoadBalancerServlet_Line1, LoadBalancerServlet_Line2</param-value>
</init-param>
<init-param>
<param-name>RetryTimeout</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>Algorithm</param-name>
<param-value>Failover</param-value>
</init-param>
<init-param>
<param-name>IsAliveURI</param-name>
<param-value>/alive/</param-value>
</init-param>
</servlet>