Configure Apache Knox load balancing

Knox provides connectivity-based failover functionality for service calls that can be made to more than one server instance in a cluster. To enable this functionality, HaProvider configuration needs to be enabled for the service and the service itself needs to be configured with more than one URL in the topology file.

Load balancing vs high availability (HA)

Currently, Knox offers load balancing using a simple round robin algorithm which prevents load on one specific node.

Because it does not support session persistence, this is not true HA, as a stateful service will not failover to other node.

Topology file parameters

To enable HA functionality for a service in Knox, add the following configuration to the topology file:
<provider>
     <role>ha</role>
     <name>HaProvider</name>
     <enabled>true</enabled>
     <param>
         <name>{SERVICE}</name>
         <value>maxFailoverAttempts=3;failoverSleep=1000;enabled=true;enableStickySession=true;enableLoadBalancing=true</value>
     </param>
</provider>
Where the configuration parameter values are:
  • maxFailoverAttempts - This is the maximum number of times a failover will be attempted. The failover strategy at this time is very simplistic in that the next URL in the list of URLs provided for the service is used and the one that failed is put at the bottom of the list. If the list is exhausted and the maximum number of attempts is not reached then the first URL will be tried again.
  • failoverSleep - The amount of time in millis that the process will wait or sleep before attempting to failover.
  • enabled - Flag to turn the particular service on or off for HA.
  • enableLoadBalancing - Round robin all the requests, distributing the load evenly across all the HA urls (no sticky sessions.)
  • enableStickySession - Round robin with sticky session.
  • noFallback - Round robin with sticky session and no fallback, requires enableStickySession to be true.
  • stickySessionCookieName - Customize sticky session cookie name, default is ‘KNOX_BACKEND-{serviceName}’.

Topology file parameters with multiple services

<provider>
     <role>ha</role>
     <name>HaProvider</name>
     <enabled>true</enabled>
     <param>
         <name>OOZIE</name>
         <value>maxFailoverAttempts=3;failoverSleep=1000;enabled=true;enableLoadBalancing=true</value>
     </param>
     <param>
         <name>HBASE</name>
         <value>maxFailoverAttempts=3;failoverSleep=1000;enabled=true;enableLoadBalancing=true</value>
     </param>
     <param>
         <name>WEBHCAT</name>
         <value>maxFailoverAttempts=3;failoverSleep=1000;enabled=true;enableLoadBalancing=true</value>
     </param>
</provider>

Service configurations

These additional URLs must be added to the service configurations:
<service>
    <role>$SERVICE</role>
    <url>http://$host1:p$ort1</url>
    <url>http://$host2:$port2</url>
</service>

Knox HA service URLs for Oozie

<service>
    <role>OOZIE</role>
    <url>http://sandbox1:11000/oozie</url>
    <url>http://sandbox2:11000/oozie</url>
</service>