Search in sources :

Example 1 with ZoneSnapshot

use of com.netflix.loadbalancer.ZoneSnapshot in project ribbon by Netflix.

the class ZoneAffinityServerListFilter method shouldEnableZoneAffinity.

private boolean shouldEnableZoneAffinity(List<T> filtered) {
    if (!zoneAffinity && !zoneExclusive) {
        return false;
    }
    if (zoneExclusive) {
        return true;
    }
    LoadBalancerStats stats = getLoadBalancerStats();
    if (stats == null) {
        return zoneAffinity;
    } else {
        logger.debug("Determining if zone affinity should be enabled with given server list: {}", filtered);
        ZoneSnapshot snapshot = stats.getZoneSnapshot(filtered);
        double loadPerServer = snapshot.getLoadPerServer();
        int instanceCount = snapshot.getInstanceCount();
        int circuitBreakerTrippedCount = snapshot.getCircuitTrippedCount();
        if (((double) circuitBreakerTrippedCount) / instanceCount >= blackOutServerPercentageThreshold.get() || loadPerServer >= activeReqeustsPerServerThreshold.get() || (instanceCount - circuitBreakerTrippedCount) < availableServersThreshold.get()) {
            logger.debug("zoneAffinity is overriden. blackOutServerPercentage: {}, activeReqeustsPerServer: {}, availableServers: {}", new Object[] { (double) circuitBreakerTrippedCount / instanceCount, loadPerServer, instanceCount - circuitBreakerTrippedCount });
            return false;
        } else {
            return true;
        }
    }
}
Also used : ZoneSnapshot(com.netflix.loadbalancer.ZoneSnapshot) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats)

Aggregations

LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)1 ZoneSnapshot (com.netflix.loadbalancer.ZoneSnapshot)1