美文网首页
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策略

    FairSharePolicy.FairShareComparator ➢ 实际最小资源份额:minShare =...

  • yum安装nginx后添加nginx-upstream-fair

    yum安装的nginx是不带nginx-upstream-fair模块的,所以在负载均衡的策略中使用fair会报错...

  • Yarn 队列调度策略

    Yarn的队列调度策略主要分三种:FIFO、Capacity调度、Fair调度。 FIFO调度策略:为先进去的任务...

  • Destiny

    Do you think destiny is fair? Or Unfair? Fair for all of ...

  • 记一首喜欢的英国民歌

    《Scarborough Fair》 主歌:Are you going to Scarborough Fair?你...

  • Inspirational College Students

    The world is not fair, the world is very fair, you get, i...

  • 无标题文章

    Vanity Fair—Vanity Fair!Here was a man, who could not spe...

  • 不公平

    it's not fair~ what is not fair?why~ i've been here four ...

  • Fair

    存档。 Fair Candy 想想那也是很久以前的事了。 地下城市桑古奈姆的空气中好像永远都弥漫着某种令人感...

  • fair

    夜晚正做着好梦,突然被冻醒。赶忙下床关电扇。怕惊醒孩子,没有敢开灯,摸黑关罢电扇返回时心里迷迷茫茫的想:哎呀,不要...

网友评论

      本文标题:Fair策略

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