private DriverTask chooseLevelAndTask() {
    long targetScheduledTime = getLevel0TargetTime();
    double worstRatio = 1;
    int selectedLevel = -1;
    for (int level = 0; level < LEVEL_THRESHOLD_SECONDS.length; level++) {
      if (!levelWaitingSplits[level].isEmpty()) {
        long levelTime = levelScheduledTime[level].get();
        double ratio = levelTime == 0 ? 0 : targetScheduledTime / (1.0 * levelTime);
        if (selectedLevel == -1 || ratio > worstRatio) {
          worstRatio = ratio;
          selectedLevel = level;
        }
      }

      targetScheduledTime /= levelTimeMultiplier;
    }

    // selected level == -1 means that the queue is empty and this method is only called when the
    // queue is not empty.
    checkState(selectedLevel != -1, "selected level can not equal to -1");
    DriverTask result = levelWaitingSplits[selectedLevel].poll();
    checkState(result != null, "result driverTask cannot be null");
    return result;
  }
We attempt to give each level a target amount of scheduled time, which is configurable using
levelTimeMultiplier.

<p>This function selects the level that has the lowest ratio of actual to the target time with
the objective of minimizing deviation from the target scheduled time. From this level, we pick
the DriverTask with the lowest scheduled time.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/schedule/queue/multilevelqueue/MultilevelPriorityQueue.java