美文网首页
Fair策略

Fair策略

作者: 专职掏大粪 | 来源:发表于2021-11-30 17:57 被阅读0次
    image.png

    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 = 资源使用量 / 权重

    image.png
    • FSQueue 中MinShare和MaxShare定义
      MinShare = MinResources
      MaxShare = max(maxResourceminShare)
      如未定义maxResource, 默认为queueMaxResourcesDefault (Integer.MAX_VALUE)

    • FSAppAttempt中MinShare和MaxShare定义
      MinShare = 0
      MaxShare = Integer.MAX_VALUE

    相关文章

      网友评论

          本文标题:Fair策略

          本文链接:https://www.haomeiwen.com/subject/jbvdxrtx.html