com.netflix.loadbalancer
Class ZoneAwareLoadBalancer<T extends Server>

java.lang.Object
  extended by com.netflix.loadbalancer.AbstractLoadBalancer
      extended by com.netflix.loadbalancer.BaseLoadBalancer
          extended by com.netflix.loadbalancer.DynamicServerListLoadBalancer<T>
              extended by com.netflix.loadbalancer.ZoneAwareLoadBalancer<T>
Type Parameters:
T -
All Implemented Interfaces:
IClientConfigAware, PrimeConnections.PrimeConnectionListener, ILoadBalancer

public class ZoneAwareLoadBalancer<T extends Server>
extends DynamicServerListLoadBalancer<T>

Load balancer that can avoid a zone as a whole when choosing server.

The key metric used to measure the zone condition is Average Active Requests, which is aggregated per rest client per zone. It is the total outstanding requests in a zone divided by number of available targeted instances (excluding circuit breaker tripped instances). This metric is very effective when timeout occurs slowly on a bad zone.

The LoadBalancer will calculate and examine zone stats of all available zones. If the Average Active Requests for any zone has reached a configured threshold, this zone will be dropped from the active server list. In case more than one zone has reached the threshold, the zone with the most active requests per server will be dropped. Once the the worst zone is dropped, a zone will be chosen among the rest with the probability proportional to its number of instances. A server will be returned from the chosen zone with a given Rule (A Rule is a load balancing strategy, for example AvailabilityFilteringRule) For each request, the steps above will be repeated. That is to say, each zone related load balancing decisions are made at real time with the up-to-date statistics aiding the choice.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.netflix.loadbalancer.AbstractLoadBalancer
AbstractLoadBalancer.ServerGroup
 
Field Summary
 
Fields inherited from class com.netflix.loadbalancer.DynamicServerListLoadBalancer
serverListUpdateInProgress
 
Fields inherited from class com.netflix.loadbalancer.BaseLoadBalancer
allServerList, allServerLock, lbStats, lbTimer, maxTotalPingTimeSeconds, name, ping, pingInProgress, pingIntervalSeconds, rule, serverComparator, upServerList, upServerLock
 
Constructor Summary
ZoneAwareLoadBalancer()
           
 
Method Summary
 Server chooseServer(java.lang.Object key)
          Choose a server from load balancer.
 void init()
          Register with monitors and start priming connections if it is set.
 void setRule(IRule rule)
           
protected  void setServerListForZones(java.util.Map<java.lang.String,java.util.List<Server>> zoneServersMap)
           
 
Methods inherited from class com.netflix.loadbalancer.DynamicServerListLoadBalancer
enableAndInitLearnNewServersFeature, forceQuickPing, getFilter, getServerListImpl, initWithNiwsConfig, setFilter, setPing, setServerListImpl, setServersList, shutdownExecutorPool, toString, updateAllServerList
 
Methods inherited from class com.netflix.loadbalancer.BaseLoadBalancer
addServer, addServers, cancelPingTask, choose, getLoadBalancerStats, getMaxTotalPingTime, getName, getPing, getPingInterval, getPrimeConnections, getRule, getServerByIndex, getServerCount, getServerList, getServerList, isEnablePrimingConnections, isPingInProgress, lockAllServerList, lockUpServerList, markServerDown, markServerDown, primeCompleted, setEnablePrimingConnections, setLoadBalancerStats, setMaxTotalPingTime, setPingInterval, setPrimeConnections
 
Methods inherited from class com.netflix.loadbalancer.AbstractLoadBalancer
chooseServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZoneAwareLoadBalancer

public ZoneAwareLoadBalancer()
Method Detail

setServerListForZones

protected void setServerListForZones(java.util.Map<java.lang.String,java.util.List<Server>> zoneServersMap)
Overrides:
setServerListForZones in class DynamicServerListLoadBalancer<T extends Server>

chooseServer

public Server chooseServer(java.lang.Object key)
Description copied from interface: ILoadBalancer
Choose a server from load balancer.

Specified by:
chooseServer in interface ILoadBalancer
Overrides:
chooseServer in class BaseLoadBalancer
Parameters:
key - An object that the load balancer may use to determine which server to return. null if the load balancer does not use this parameter.
Returns:
server chosen

setRule

public void setRule(IRule rule)
Overrides:
setRule in class DynamicServerListLoadBalancer<T extends Server>

init

public void init()
Description copied from class: BaseLoadBalancer
Register with monitors and start priming connections if it is set.

Overrides:
init in class BaseLoadBalancer