code: int getCap(int totalRunnableTasks, int localMaxTasks, int totalSlots) {
      double load = maxDiff + ((double)totalRunnableTasks) / totalSlots;
      int cap = (int) Math.min(localMaxTasks, Math.ceil(load * localMaxTasks));
      if (LOG.isDebugEnabled()) {
        LOG.debug("load:" + load + " maxDiff:" + maxDiff +
            " totalRunnable:" + totalRunnableTasks + " totalSlots:" + totalSlots +
            " localMaxTasks:" + localMaxTasks +
            " cap:" + cap);
      }
      return cap;
    }
docs: Determine how many tasks of a given type we want to run on a TaskTracker.
  This cap is chosen based on how many tasks of that type are outstanding in
  total, so that when the cluster is used below capacity, tasks are spread
  out uniformly across the nodes rather than being clumped up on whichever
  machines sent out heartbeats earliest.