@Override
    public void run() {
      for (Map.Entry<String, AtomicLong> hostAndRequestCount : hostToRequestCount.entrySet()) {
        String hostname = hostAndRequestCount.getKey();
        AtomicLong requestCount = hostAndRequestCount.getValue();
        Long hostSleepTime = hostToSleepTime.get(hostname);
        long currentQPS = requestCount.get();
        logger.info("For host {}, request count per sec is {}, current sleep time is {} ms", hostname, currentQPS,
            hostSleepTime);
        if (targetQPS > 0 && currentQPS > 0) {
          // formula to update sleep time is: new sleep time = (currentQPS / targetQPS) * (current sleep time)
          long newSleepTime = currentQPS * hostSleepTime / targetQPS;
          // if currentQPS is already higher than target one and new sleep time still equals current sleep time, we
          // explicitly plus one more millisecond.
          newSleepTime = newSleepTime + ((currentQPS > targetQPS && newSleepTime == hostSleepTime) ? 1 : 0);
          hostSleepTime = newSleepTime;
          requestCount.set(0);
          logger.info("Updated sleep time is {} ms for host {}", hostSleepTime, hostname);
        }
        hostToSleepTime.put(hostname, hostSleepTime);
      }
    }
A periodic updater that adjusts sleep time for connections based on current QPS and target QPS.
ambry-tools/src/main/java/com/github/ambry/tools/perf/rest/NettyPerfClient.java