Search in sources :

Example 6 with InvocationStatDimension

use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.

the class WeightDegradeStrategy method degrade.

@Override
public void degrade(MeasureResultDetail measureResultDetail) {
    super.degrade(measureResultDetail);
    if (measureResultDetail.isLogOnly()) {
        return;
    }
    InvocationStatDimension statDimension = measureResultDetail.getInvocationStatDimension();
    String appName = statDimension.getAppName();
    ProviderInfo providerInfo = statDimension.getProviderInfo();
    // if provider is removed or provider is warming up
    if (providerInfo == null || providerInfo.getStatus() == ProviderStatus.WARMING_UP) {
        return;
    }
    int currentWeight = ProviderInfoWeightManager.getWeight(providerInfo);
    double weightDegradeRate = FaultToleranceConfigManager.getWeightDegradeRate(appName);
    int degradeLeastWeight = FaultToleranceConfigManager.getDegradeLeastWeight(appName);
    int degradeWeight = CalculateUtils.multiply(currentWeight, weightDegradeRate);
    degradeWeight = degradeWeight < degradeLeastWeight ? degradeLeastWeight : degradeWeight;
    // degrade weight of this provider info
    boolean success = ProviderInfoWeightManager.degradeWeight(providerInfo, degradeWeight);
    if (success && LOGGER.isInfoEnabled(appName)) {
        LOGGER.infoWithApp(appName, "the weight was degraded. serviceUniqueName:[" + statDimension.getService() + "],ip:[" + statDimension.getIp() + "],origin weight:[" + currentWeight + "],degraded weight:[" + degradeWeight + "].");
    }
}
Also used : ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension)

Example 7 with InvocationStatDimension

use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.

the class LogPrintDegradeStrategy method degrade.

@Override
public void degrade(MeasureResultDetail measureResultDetail) {
    InvocationStatDimension statDimension = measureResultDetail.getInvocationStatDimension();
    String appName = statDimension.getAppName();
    if (LOGGER.isInfoEnabled(appName)) {
        String service = statDimension.getService();
        long timeWindow = measureResultDetail.getTimeWindow();
        long windowCount = measureResultDetail.getWindowCount();
        double abnormalRate = measureResultDetail.getAbnormalRate();
        double averageAbnormalRate = measureResultDetail.getAverageAbnormalRate();
        String ip = statDimension.getIp();
        LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGULATION_ABNORMAL, timeWindow, service, appName, windowCount, abnormalRate, averageAbnormalRate, ip));
    }
}
Also used : InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension)

Example 8 with InvocationStatDimension

use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.

the class ServiceHorizontalMeasureStrategy method getInvocationStatSnapshots.

/**
 * 对批量Invocation对应的InvocationStat进行一个快照
 *
 * @param stats Dimensions of invocation statistics
 * @return List<InvocationStat>
 */
public static List<InvocationStat> getInvocationStatSnapshots(List<InvocationStat> stats) {
    List<InvocationStat> snapshots = new ArrayList<InvocationStat>(stats.size());
    for (InvocationStat stat : stats) {
        InvocationStat snapshot = stat.snapshot();
        if (snapshot.getInvokeCount() <= 0) {
            if (stat.getUselessCycle().incrementAndGet() > 6) {
                // 6 个时间窗口无调用,删除统计
                InvocationStatFactory.removeInvocationStat(stat);
                InvocationStatDimension dimension = stat.getDimension();
                String appName = dimension.getAppName();
                if (LOGGER.isDebugEnabled(appName)) {
                    LOGGER.debugWithApp(appName, "Remove invocation stat : {}, {} because of useless cycle > 6", dimension.getDimensionKey(), dimension.getProviderInfo());
                }
            }
        } else {
            stat.getUselessCycle().set(0);
            snapshots.add(snapshot);
        }
    }
    return snapshots;
}
Also used : InvocationStat(com.alipay.sofa.rpc.client.aft.InvocationStat) InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension) ArrayList(java.util.ArrayList)

Example 9 with InvocationStatDimension

use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.

the class ServiceHorizontalRegulationStrategy method isReachMaxDegradeIpCount.

@Override
public boolean isReachMaxDegradeIpCount(MeasureResultDetail measureResultDetail) {
    InvocationStatDimension statDimension = measureResultDetail.getInvocationStatDimension();
    ConcurrentHashSet<String> ips = getDegradeProviders(statDimension.getDimensionKey());
    String ip = statDimension.getIp();
    if (ips.contains(ip)) {
        return false;
    } else {
        int degradeMaxIpCount = FaultToleranceConfigManager.getDegradeMaxIpCount(statDimension.getAppName());
        ipsLock.lock();
        try {
            if (ips.size() < degradeMaxIpCount) {
                ips.add(ip);
                return false;
            } else {
                return true;
            }
        } finally {
            ipsLock.unlock();
        }
    }
}
Also used : InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension)

Example 10 with InvocationStatDimension

use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.

the class ServiceHorizontalRegulationStrategy method isExistInTheDegradeList.

@Override
public boolean isExistInTheDegradeList(MeasureResultDetail measureResultDetail) {
    InvocationStatDimension statDimension = measureResultDetail.getInvocationStatDimension();
    ConcurrentHashSet<String> ips = getDegradeProviders(statDimension.getDimensionKey());
    return ips != null && ips.contains(statDimension.getIp());
}
Also used : InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension)

Aggregations

InvocationStatDimension (com.alipay.sofa.rpc.client.aft.InvocationStatDimension)11 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)2 InvocationStat (com.alipay.sofa.rpc.client.aft.InvocationStat)2 MeasureModel (com.alipay.sofa.rpc.client.aft.MeasureModel)2 MeasureResult (com.alipay.sofa.rpc.client.aft.MeasureResult)1 MeasureResultDetail (com.alipay.sofa.rpc.client.aft.MeasureResultDetail)1 ArrayList (java.util.ArrayList)1