Fair策略

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一.简述如何安装配置apache 的一个开源的hadoop 1.使用root账户登陆 2.修改ip 3.修改hos...
    栀子花_ef39阅读 4,995评论 0 52
  • 一、概念 1.1 什么是调度器 理想情况下,我们应用对Yarn资源的请求应该立刻得到满足,但现实情况资源往往是有限...
    CJ21阅读 1,578评论 0 2
  • 1 前言 1 大规模数据如何检索 当系统数据量上了10亿、100亿条的时候,我们在做系统架构的时候通常会从以下角度...
    MiniSoulBigBang阅读 1,354评论 0 5
  • Hadoop最初的设计目的是支持大数据批处理作业,如日志挖掘、Web索引等作业,为此,Hadoop仅提供了一个非常...
    tracy_668阅读 1,296评论 0 4
  • Tomcat 容器内的优化 一、 tomcat的3种运行模式 1、 bio 默认的模式,性能非常低下,没有经过任何...
    Tucke阅读 9,149评论 0 52