com.netflix.loadbalancer
Class WeightedResponseTimeRule

java.lang.Object
  extended by com.netflix.loadbalancer.AbstractLoadBalancerRule
      extended by com.netflix.loadbalancer.RoundRobinRule
          extended by com.netflix.loadbalancer.WeightedResponseTimeRule
All Implemented Interfaces:
com.netflix.client.IClientConfigAware, IRule

public class WeightedResponseTimeRule
extends RoundRobinRule

Rule that use the average/percentile response times to assign dynamic "weights" per Server which is then used in the "Weighted Round Robin" fashion.

The basic idea for weighted round robin has been obtained from JCS The implementation for choosing the endpoint from the list of endpoints is as follows:Let's assume 4 endpoints:A(wt=10), B(wt=30), C(wt=40), D(wt=20).

Using the Random API, generate a random number between 1 and10+30+40+20. Let's assume that the above list is randomized. Based on the weights, we have intervals as follows:

1-----10 (A's weight)
11----40 (A's weight + B's weight)
41----80 (A's weight + B's weight + C's weight)
81----100(A's weight + B's weight + C's weight + C's weight)

Here's the psuedo code for deciding where to send the request:

if (random_number between 1 & 10) {send request to A;}
else if (random_number between 11 & 40) {send request to B;}
else if (random_number between 41 & 80) {send request to C;}
else if (random_number between 81 & 100) {send request to D;}

When there is not enough statistics gathered for the servers, this rule will fall back to use RoundRobinRule.


Field Summary
static int DEFAULT_TIMER_INTERVAL
           
protected  java.util.concurrent.atomic.AtomicBoolean serverWeightAssignmentInProgress
           
protected  java.util.Timer serverWeightTimer
           
static com.netflix.client.config.IClientConfigKey<java.lang.Integer> WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY
           
 
Constructor Summary
WeightedResponseTimeRule()
           
WeightedResponseTimeRule(ILoadBalancer lb)
           
 
Method Summary
 Server choose(ILoadBalancer lb, java.lang.Object key)
           
 void initWithNiwsConfig(com.netflix.client.config.IClientConfig clientConfig)
           
 void setLoadBalancer(ILoadBalancer lb)
           
 void shutdown()
           
 
Methods inherited from class com.netflix.loadbalancer.RoundRobinRule
choose
 
Methods inherited from class com.netflix.loadbalancer.AbstractLoadBalancerRule
getLoadBalancer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY

public static final com.netflix.client.config.IClientConfigKey<java.lang.Integer> WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY

DEFAULT_TIMER_INTERVAL

public static final int DEFAULT_TIMER_INTERVAL
See Also:
Constant Field Values

serverWeightTimer

protected java.util.Timer serverWeightTimer

serverWeightAssignmentInProgress

protected java.util.concurrent.atomic.AtomicBoolean serverWeightAssignmentInProgress
Constructor Detail

WeightedResponseTimeRule

public WeightedResponseTimeRule()

WeightedResponseTimeRule

public WeightedResponseTimeRule(ILoadBalancer lb)
Method Detail

setLoadBalancer

public void setLoadBalancer(ILoadBalancer lb)
Specified by:
setLoadBalancer in interface IRule
Overrides:
setLoadBalancer in class AbstractLoadBalancerRule

shutdown

public void shutdown()

choose

public Server choose(ILoadBalancer lb,
                     java.lang.Object key)
Overrides:
choose in class RoundRobinRule

initWithNiwsConfig

public void initWithNiwsConfig(com.netflix.client.config.IClientConfig clientConfig)
Specified by:
initWithNiwsConfig in interface com.netflix.client.IClientConfigAware
Overrides:
initWithNiwsConfig in class RoundRobinRule