Skip to content

Commit

Permalink
优化客户端自适应负载均衡效果,修复客户端生产不均匀问题
Browse files Browse the repository at this point in the history
  • Loading branch information
gaohaoxiang committed Sep 25, 2020
1 parent e619b32 commit 25bfadd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public Node doAdaptiveSelect(Nodes nodes) {
double compute = scoreJudge.compute(nodes, node);
score += (compute / 100 * scoreJudge.getRatio());
}
if (score > 0) {
weightNodes.add(new WeightNode(node, score));
}
weightNodes.add(new WeightNode(node, score));
}
return weightSelect(weightNodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
*/
public class AvgScoreJudge implements ScoreJudge {

public static int threshhold = 500;
public static int exceptionThreshhold = 500;

@Override
public double compute(Nodes nodes, Node node) {
double score = node.getMetric().getAvg() / nodes.getMetric().getAvg() * 100;
double maxAvg = 0;
for (Node otherNode : nodes.getNodes()) {
if (!otherNode.getUrl().equals(node.getUrl())) {
maxAvg = Math.max(maxAvg, otherNode.getMetric().getAvg());
}
}

double score = node.getMetric().getAvg() / maxAvg * 100;

if (score > threshhold) {
if (score > exceptionThreshhold) {
return -Integer.MAX_VALUE;
} else {
return 100;
Expand Down

0 comments on commit 25bfadd

Please sign in to comment.