FairSharePolicy.FairShareComparator
@Override
public int compare(Schedulable s1, Schedulable s2) {
double minShareRatio1, minShareRatio2;
double useToWeightRatio1, useToWeightRatio2;
double weight1, weight2;
Resource minShare1 = Resources.min(RESOURCE_CALCULATOR, null,
s1.getMinShare(), s1.getDemand());
Resource minShare2 = Resources.min(RESOURCE_CALCULATOR, null,
s2.getMinShare(), s2.getDemand());
boolean s1Needy = Resources.lessThan(RESOURCE_CALCULATOR, null,
s1.getResourceUsage(), minShare1);
boolean s2Needy = Resources.lessThan(RESOURCE_CALCULATOR, null,
s2.getResourceUsage(), minShare2);
minShareRatio1 = (double) s1.getResourceUsage().getMemory()
/ Resources.max(RESOURCE_CALCULATOR, null, minShare1, ONE).getMemory();
minShareRatio2 = (double) s2.getResourceUsage().getMemory()
/ Resources.max(RESOURCE_CALCULATOR, null, minShare2, ONE).getMemory();
weight1 = s1.getWeights().getWeight(ResourceType.MEMORY);
weight2 = s2.getWeights().getWeight(ResourceType.MEMORY);
if (weight1 > 0.0 && weight2 > 0.0) {
useToWeightRatio1 = s1.getResourceUsage().getMemory() / weight1;
useToWeightRatio2 = s2.getResourceUsage().getMemory() / weight2;
} else { // Either weight1 or weight2 equals to 0
if (weight1 == weight2) {
// If they have same weight, just compare usage
useToWeightRatio1 = s1.getResourceUsage().getMemory();
useToWeightRatio2 = s2.getResourceUsage().getMemory();
} else {
// By setting useToWeightRatios to negative weights, we give the
// zero-weight one less priority, so the non-zero weight one will
// be given slots.
useToWeightRatio1 = -weight1;
useToWeightRatio2 = -weight2;
}
}
int res = 0;
if (s1Needy && !s2Needy)
res = -1;
else if (s2Needy && !s1Needy)
res = 1;
else if (s1Needy && s2Needy)
res = (int) Math.signum(minShareRatio1 - minShareRatio2);
else
// Neither schedulable is needy
res = (int) Math.signum(useToWeightRatio1 - useToWeightRatio2);
if (res == 0) {
// Apps are tied in fairness ratio. Break the tie by submit time and job
// name to get a deterministic ordering, which is useful for unit tests.
res = (int) Math.signum(s1.getStartTime() - s2.getStartTime());
if (res == 0) {
res = s1.getName().compareTo(s2.getName());
}
}
return res;
}
? 實際最小資源份額:minShare = Min(資源需求量Demand港庄,配置的最小資源MinShare)
? 是否饑餓:isNeedy = 資源使用量 < minShare(實際最小資源份額)
? 資源分配比:minShareRatio = 資源使用量 / Max(mindshare, 1)
? 資源使用權重比:useToWeightRatio = 資源使用量 / 權重
FSQueue 中MinShare和MaxShare定義
MinShare
=MinResources
MaxShare
= max(maxResource
恕曲,minShare
)
如未定義maxResource, 默認為queueMaxResourcesDefault (Integer.MAX_VALUE
)FSAppAttempt中MinShare和MaxShare定義
MinShare = 0
MaxShare = Integer.MAX_VALUE