com.netflix.loadbalancer
Class ResponseTimeWeightedRule
java.lang.Object
com.netflix.loadbalancer.ResponseTimeWeightedRule
- All Implemented Interfaces:
- IRule
public class ResponseTimeWeightedRule
- extends java.lang.Object
- implements IRule
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;}
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
serverWeightTimer
protected java.util.Timer serverWeightTimer
serverWeightAssignmentInProgress
protected java.util.concurrent.atomic.AtomicBoolean serverWeightAssignmentInProgress
ResponseTimeWeightedRule
public ResponseTimeWeightedRule()
getLoadBalancer
public ILoadBalancer getLoadBalancer()
setLoadBalancer
public void setLoadBalancer(ILoadBalancer lb)
initialize
public void initialize(ILoadBalancer lb)
shutdown
public void shutdown()
choose
public Server choose(BaseLoadBalancer lb,
java.lang.Object key)
- Specified by:
choose
in interface IRule