Decreases the session pool size in response to error messages from the server requesting to rate-limit
        requests. We decrease by one session per call.
496485
def decrease_poolsize(self):
        
        # Take a single session from the pool and discard it. We need to protect this with a lock while we are changing
        # the pool size variable, to avoid race conditions. We must keep at least one session in the pool.
        if self._session_pool_size <= 1:
            raise SessionPoolMinSizeReached('Session pool size cannot be decreased further')
        with self._session_pool_lock:
            if self._session_pool_size <= 1:
                log.debug('Session pool size was decreased in another thread')
                return
            log.warning('Lowering session pool size from %s to %s', self._session_pool_size,
                        self._session_pool_size - 1)
            self.get_session().close()
            self._session_pool_size -= 1
825546
def purge_all(self, rate_limit_delay=60):
        ''''''

        for batch, response in self.purge():
            if response.status_code == 507:
                details = response.json().get('detail', '<response did not contain "detail">')
                logger.info('Will retry request in %d seconds due to API rate-limit: %s',
                            rate_limit_delay, details)
                time.sleep(rate_limit_delay)
654949
def rate_limit(self, rate_limit):
        
        self._rate_limit = bool(rate_limit)
        self._rate_limit_last_call = None
        self.clear_memoized()
158112
void decreaseNumberOfPendingInstances(final InstanceType instanceType) {

		Integer numberOfRemainingInstances = this.pendingRequests.get(instanceType);
		if (numberOfRemainingInstances == null) {
			return;
		}

		numberOfRemainingInstances = Integer.valueOf(numberOfRemainingInstances.intValue() - 1);
		if (numberOfRemainingInstances.intValue() == 0) {
			this.pendingRequests.remove(instanceType);
		} else {
			this.pendingRequests.put(instanceType, numberOfRemainingInstances);
		}
	}
738375
def _on_throttle(self, conn, command, kwargs, response, capacity, seconds):
        
        LOG.info(
            "Throughput limit exceeded during %s. " "Sleeping for %d second%s",
            command,
            seconds,
            plural(seconds),
        )
542524
def rate_limit(self, name, limit=5, per=60, debug=False):
        
        return RateLimit(self, name, limit, per, debug)
438937
private function checkDaemonLimits(): void
    {
        if ($this->isShutdown) {
            throw new ShutdownException($this->shutdownMessage);
        }

        pcntl_signal_dispatch();

        if (DaemonOptions::NO_LIMIT !== $this->requestLimit) {
            if ($this->requestLimit <= $this->requestCount) {
                throw new ShutdownException('Daemon request limit reached ('.$this->requestCount.' of '.$this->requestLimit.')');
            }
        }

        if (DaemonOptions::NO_LIMIT !== $this->memoryLimit) {
            $memoryUsage = memory_get_usage(true);

            if ($this->memoryLimit <= $memoryUsage) {
                throw new ShutdownException('Daemon memory limit reached ('.$memoryUsage.' of '.$this->memoryLimit.' bytes)');
            }
        }
    }
1151956
private void throttledTransfer(MockResponse policy, Socket socket, BufferedSource source,
      BufferedSink sink, long byteCount, boolean isRequest) throws IOException {
    if (byteCount == 0) return;

    Buffer buffer = new Buffer();
    long bytesPerPeriod = policy.getThrottleBytesPerPeriod();
    long periodDelayMs = policy.getThrottlePeriod(TimeUnit.MILLISECONDS);

    long halfByteCount = byteCount / 2;
    boolean disconnectHalfway = isRequest
        ? policy.getSocketPolicy() == DISCONNECT_DURING_REQUEST_BODY
        : policy.getSocketPolicy() == DISCONNECT_DURING_RESPONSE_BODY;

    while (!socket.isClosed()) {
      for (long b = 0; b < bytesPerPeriod; ) {
        // Ensure we do not read past the allotted bytes in this period.
        long toRead = Math.min(byteCount, bytesPerPeriod - b);
        // Ensure we do not read past halfway if the policy will kill the connection.
        if (disconnectHalfway) {
          toRead = Math.min(toRead, byteCount - halfByteCount);
        }

        long read = source.read(buffer, toRead);
        if (read == -1) return;

        sink.write(buffer, read);
        sink.flush();
        b += read;
        byteCount -= read;

        if (disconnectHalfway && byteCount == halfByteCount) {
          socket.close();
          return;
        }

        if (byteCount == 0) return;
      }

      if (periodDelayMs != 0) {
        try {
          Thread.sleep(periodDelayMs);
        } catch (InterruptedException e) {
          throw new AssertionError(e);
        }
      }
    }
  }
103269
def delete_bandwidth_limit_rule(self, rule, policy):
        """"""
        return self.delete(self.qos_bandwidth_limit_rule_path %
                           (policy, rule))
1289071
function(opt_maxPoolSize) {
  /**
   * The max pool size as configured.
   *
   * @private {number}
   */
  this.maxPoolSizeConfigured_ =
      opt_maxPoolSize || ForwardChannelRequestPool.MAX_POOL_SIZE_;

  /**
   * The current size limit of the request pool. This limit is meant to be
   * read-only after the channel is fully opened.
   *
   * If SPDY or HTTP2 is enabled, set it to the max pool size, which is also
   * configurable.
   *
   * @private {number}
   */
  this.maxSize_ = ForwardChannelRequestPool.isSpdyOrHttp2Enabled_() ?
      this.maxPoolSizeConfigured_ :
      1;

  /**
   * The container for all the pending request objects.
   *
   * @private {Set<ChannelRequest>}
   */
  this.requestPool_ = null;

  if (this.maxSize_ > 1) {
    this.requestPool_ = new Set();
  }

  /**
   * The single request object when the pool size is limited to one.
   *
   * @private {ChannelRequest}
   */
  this.request_ = null;

  /**
   * Saved pending messages when the pool is cancelled.
   *
   * @private {!Array<Wire.QueuedMap>}
   */
  this.pendingMessages_ = [];
}
356956
public void removeHttpSession(HttpSession session) {
		if (session == activeSession) {
			activeSession = null;
		}
		synchronized (this.sessions) {
			this.sessions.remove(session);
		}
		this.model.removeHttpSession(session);
		session.invalidate();
	}
496549
def _update_callsafety(self, response):
        
        if self.ratelimit is not None:
            self.callsafety['lastcalltime'] = time()
            self.callsafety['lastlimitremaining'] = int(response.headers.get('X-Rate-Limit-Remaining', 0))
1051243
public void removeHttpSession(final HttpSession session) {
		if (View.isInitialised() && !EventQueue.isDispatchThread()) {
			EventQueue.invokeLater(new Runnable() {

				@Override
				public void run() {
					removeHttpSession(session);
				}
			});

			return;
		}

		int index = sessions.indexOf(session);
		sessions.remove(index);
		fireTableRowsDeleted(index, index);
	}
1231282
int removeSessionToSessions(Session session, Collection<Session> sessions) {
		if (sessions != null) {
			if (sessions.remove(session)) {
				return 1;
			}
		}
		return 0;
	}
295016
public void resetLimits() {
        maxLength = Long.MAX_VALUE;
        timeoutMs = Long.MAX_VALUE;
        maxRateBytesPerMs = Long.MAX_VALUE;
    }
667977
def shutdown_instances(self):
        
        self.min_size = 0
        self.max_size = 0
        self.desired_capacity = 0
        self.update()
431960
public void shrink (int maximumCapacity) {
		if (maximumCapacity < 0) throw new IllegalArgumentException("maximumCapacity must be >= 0: " + maximumCapacity);
		if (size > maximumCapacity) maximumCapacity = size;
		if (capacity <= maximumCapacity) return;
		maximumCapacity = nextPowerOfTwo(maximumCapacity);
		resize(maximumCapacity);
	}