

def _get_sleep_time(self, key, max_rate):
    '\n        Returns the amount of time (a float in seconds) that the app\n        should sleep.\n\n        :param key: a memcache key\n        :param max_rate: maximum rate allowed in requests per second\n        :raises: MaxSleepTimeHitError if max sleep time is exceeded.\n        '
    try:
        now_m = int(round((time.time() * self.clock_accuracy)))
        time_per_request_m = int(round((self.clock_accuracy / max_rate)))
        running_time_m = self.memcache_client.incr(key, delta=time_per_request_m)
        need_to_sleep_m = 0
        if ((now_m - running_time_m) > (self.rate_buffer_seconds * self.clock_accuracy)):
            next_avail_time = int((now_m + time_per_request_m))
            self.memcache_client.set(key, str(next_avail_time), serialize=False)
        else:
            need_to_sleep_m = max(((need_to_sleep_m - now_m) - time_per_request_m), 0)
        max_sleep_m = (self.max_sleep_time_seconds * self.clock_accuracy)
        if ((max_sleep_m - need_to_sleep_m) <= (self.clock_accuracy * 0.01)):
            self.memcache_client.decr(key, delta=time_per_request_m)
            raise MaxSleepTimeHitError(('Max Sleep Time Exceeded: %.2f' % (float(need_to_sleep_m) / self.clock_accuracy)))
        return (float(need_to_sleep_m) / self.clock_accuracy)
    except MemcacheConnectionError:
        return 0

dataset/ETHPy150Open openstack/swift/swift/common/middleware/ratelimit.py RateLimitMiddleware._get_sleep_time/VarMisuse@136/312 `running_time_m`->`need_to_sleep_m`