/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
The AIMDBackoffManager
applies an additive increase,
* multiplicative decrease (AIMD) to managing a dynamic limit to
* the number of connections allowed to a given host. You may want
* to experiment with the settings for the cooldown periods and the
* backoff factor to get the adaptive behavior you want.
Generally speaking, shorter cooldowns will lead to more steady-state * variability but faster reaction times, while longer cooldowns * will lead to more stable equilibrium behavior but slower reaction * times.
* *Similarly, higher backoff factors promote greater * utilization of available capacity at the expense of fairness * among clients. Lower backoff factors allow equal distribution of * capacity among clients (fairness) to happen faster, at the * expense of having more server capacity unused in the short term.
* * @since 4.2 */ public class AIMDBackoffManager implements BackoffManager { private final ConnPoolControlAIMDBackoffManager
to manage
* per-host connection pool sizes represented by the
* given {@link ConnPoolControl}.
* @param connPerRoute per-host routing maximums to
* be managed
*/
public AIMDBackoffManager(final ConnPoolControlMath.floor
is applied in the
* case of non-integer outcomes to ensure we actually
* decrease the pool size. Pool sizes are never decreased
* below 1, however. Defaults to 0.5.
* @param d must be between 0.0 and 1.0, exclusive.
*/
public void setBackoffFactor(final double d) {
Args.check(d > 0.0 && d < 1.0, "Backoff factor must be 0.0 < f < 1.0");
backoffFactor = d;
}
/**
* Sets the amount of time, in milliseconds, to wait between
* adjustments in pool sizes for a given host, to allow
* enough time for the adjustments to take effect. Defaults
* to 5000L (5 seconds).
* @param l must be positive
*/
public void setCooldownMillis(final long l) {
Args.positive(coolDown, "Cool down");
coolDown = l;
}
/**
* Sets the absolute maximum per-host connection pool size to
* probe up to; defaults to 2 (the default per-host max).
* @param cap must be >= 1
*/
public void setPerHostConnectionCap(final int cap) {
Args.positive(cap, "Per host connection cap");
this.cap = cap;
}
}