Browse Source

[Improvement][server]lower weight round robin support weight (#3768)

* [Improvement][server]lower weight round robin  support weight

* delete  code

* resolve conflicts
pull/3/MERGE
CalvinKirs 4 years ago committed by GitHub
parent
commit
11d3c2cdaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/dispatch/host/assign/HostWeight.java
  2. 13
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/dispatch/host/assign/LowerWeightRoundRobin.java

19
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/dispatch/host/assign/HostWeight.java

@ -33,9 +33,9 @@ public class HostWeight {
private final Host host; private final Host host;
private final int weight; private final double weight;
private int currentWeight; private double currentWeight;
public HostWeight(Host host, double cpu, double memory, double loadAverage) { public HostWeight(Host host, double cpu, double memory, double loadAverage) {
this.weight = getWeight(cpu, memory, loadAverage, host); this.weight = getWeight(cpu, memory, loadAverage, host);
@ -43,15 +43,15 @@ public class HostWeight {
this.currentWeight = weight; this.currentWeight = weight;
} }
public int getCurrentWeight() { public double getCurrentWeight() {
return currentWeight; return currentWeight;
} }
public int getWeight() { public double getWeight() {
return weight; return weight;
} }
public void setCurrentWeight(int currentWeight) { public void setCurrentWeight(double currentWeight) {
this.currentWeight = currentWeight; this.currentWeight = currentWeight;
} }
@ -68,20 +68,19 @@ public class HostWeight {
+ '}'; + '}';
} }
private int getWeight(double cpu, double memory, double loadAverage, Host host) { private double getWeight(double cpu, double memory, double loadAverage, Host host) {
int calculateWeight = (int) (cpu * CPU_FACTOR + memory * MEMORY_FACTOR + loadAverage * LOAD_AVERAGE_FACTOR); double calculateWeight = cpu * CPU_FACTOR + memory * MEMORY_FACTOR + loadAverage * LOAD_AVERAGE_FACTOR;
return getWarmUpWeight(host, calculateWeight); return getWarmUpWeight(host, calculateWeight);
} }
/** /**
* If the warm-up is not over, add the weight * If the warm-up is not over, add the weight
*/ */
private int getWarmUpWeight(Host host, int weight) { private double getWarmUpWeight(Host host, double weight) {
long startTime = host.getStartTime(); long startTime = host.getStartTime();
long uptime = System.currentTimeMillis() - startTime; long uptime = System.currentTimeMillis() - startTime;
if (uptime > 0 && uptime < Constants.WARM_UP_TIME) { if (uptime > 0 && uptime < Constants.WARM_UP_TIME) {
return (int) ((weight * Constants.WARM_UP_TIME) / uptime); return weight * Constants.WARM_UP_TIME / uptime;
} }
return weight; return weight;
} }

13
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/dispatch/host/assign/LowerWeightRoundRobin.java

@ -20,24 +20,25 @@ package org.apache.dolphinscheduler.server.master.dispatch.host.assign;
import java.util.Collection; import java.util.Collection;
/** /**
* lower weight round robin * lower weight round robin
*/ */
public class LowerWeightRoundRobin extends AbstractSelector<HostWeight>{ public class LowerWeightRoundRobin extends AbstractSelector<HostWeight> {
/** /**
* select * select
*
* @param sources sources * @param sources sources
* @return HostWeight * @return HostWeight
*/ */
@Override @Override
public HostWeight doSelect(Collection<HostWeight> sources){ public HostWeight doSelect(Collection<HostWeight> sources) {
int totalWeight = 0; double totalWeight = 0;
int lowWeight = 0; double lowWeight = 0;
HostWeight lowerNode = null; HostWeight lowerNode = null;
for (HostWeight hostWeight : sources) { for (HostWeight hostWeight : sources) {
totalWeight += hostWeight.getWeight(); totalWeight += hostWeight.getWeight();
hostWeight.setCurrentWeight(hostWeight.getCurrentWeight() + hostWeight.getWeight()); hostWeight.setCurrentWeight(hostWeight.getCurrentWeight() + hostWeight.getWeight());
if (lowerNode == null || lowWeight > hostWeight.getCurrentWeight() ) { if (lowerNode == null || lowWeight > hostWeight.getCurrentWeight()) {
lowerNode = hostWeight; lowerNode = hostWeight;
lowWeight = hostWeight.getCurrentWeight(); lowWeight = hostWeight.getCurrentWeight();
} }

Loading…
Cancel
Save