public class FairStrategy extends Object implements LoadBalanceStrategy
Algorithm overview: The fair load balancing policy dynamically adjusts the weight of each server and divides it by weight. Rpc client maintains a latency window record rpc time for each server, after processing a traffic, the server updates its own window. If the mean value of the service in the window > the overall mean of the service, reduce its own weight. On the contrary, increase its own weight. When the window is not full, the polling does not adjust the weight.
| 构造器和说明 |
|---|
FairStrategy() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected int |
calculateWeight(BrpcChannelGroup group,
int timeOut)
Calculate the weight of a rpc server
|
void |
destroy() |
protected BrpcChannelGroup |
fairSelect(com.baidu.brpc.client.loadbalance.FairStrategy.Node root) |
protected com.baidu.brpc.client.loadbalance.FairStrategy.Node |
generateWeightTreeByLeafNodes(Queue<com.baidu.brpc.client.loadbalance.FairStrategy.Node> leafNodes)
generate the tree by leaf nodes
the leaf nodes are the real rpc servers
the parent nodes used to calculate the sum of it's children's weight
|
protected long |
getRandomLong() |
void |
init(RpcClient rpcClient) |
void |
markInvalidInstance(List<BrpcChannelGroup> instances)
Since the weight tree will update by a period of time, so if there's any invalid instance,
the business should notify the fair strategy.
|
protected BrpcChannelGroup |
randomSelect(CopyOnWriteArrayList<BrpcChannelGroup> instances) |
protected com.baidu.brpc.client.loadbalance.FairStrategy.Node |
searchNode(com.baidu.brpc.client.loadbalance.FairStrategy.Node parent,
int weight) |
BrpcChannelGroup |
selectInstance(CopyOnWriteArrayList<BrpcChannelGroup> instances) |
protected void |
updateWeightTree()
Update weight of each node of the tree.
|
public void init(RpcClient rpcClient)
init 在接口中 LoadBalanceStrategypublic BrpcChannelGroup selectInstance(CopyOnWriteArrayList<BrpcChannelGroup> instances)
selectInstance 在接口中 LoadBalanceStrategypublic void destroy()
destroy 在接口中 LoadBalanceStrategypublic void markInvalidInstance(List<BrpcChannelGroup> instances)
protected BrpcChannelGroup randomSelect(CopyOnWriteArrayList<BrpcChannelGroup> instances)
protected long getRandomLong()
protected BrpcChannelGroup fairSelect(com.baidu.brpc.client.loadbalance.FairStrategy.Node root)
protected com.baidu.brpc.client.loadbalance.FairStrategy.Node searchNode(com.baidu.brpc.client.loadbalance.FairStrategy.Node parent,
int weight)
protected void updateWeightTree()
treeContainerprotected int calculateWeight(BrpcChannelGroup group, int timeOut)
group - The BrpcChannelGroup instance of a rpc servertimeOut - Read timeout in millisprotected com.baidu.brpc.client.loadbalance.FairStrategy.Node generateWeightTreeByLeafNodes(Queue<com.baidu.brpc.client.loadbalance.FairStrategy.Node> leafNodes)
leafNodes - leaf nodes listCopyright © 2019 Baidu, Inc.. All rights reserved.