Search in sources :

Example 1 with MeasureResult

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

the class ServiceHorizontalMeasureStrategy method measure.

@Override
public MeasureResult measure(MeasureModel measureModel) {
    MeasureResult measureResult = new MeasureResult();
    measureResult.setMeasureModel(measureModel);
    String appName = measureModel.getAppName();
    List<InvocationStat> stats = measureModel.getInvocationStats();
    if (!CommonUtils.isNotEmpty(stats)) {
        return measureResult;
    }
    // 如果有被新剔除的InvocationStat,则不会存在于该次获取结果中。
    List<InvocationStat> invocationStats = getInvocationStatSnapshots(stats);
    long timeWindow = FaultToleranceConfigManager.getTimeWindow(appName);
    /* leastWindowCount在同一次度量中保持不变*/
    long leastWindowCount = FaultToleranceConfigManager.getLeastWindowCount(appName);
    leastWindowCount = leastWindowCount < LEGAL_LEAST_WINDOW_COUNT ? LEGAL_LEAST_WINDOW_COUNT : leastWindowCount;
    /* 计算平均异常率和度量单个ip的时候都需要使用到appWeight*/
    double averageExceptionRate = calculateAverageExceptionRate(invocationStats, leastWindowCount);
    double leastWindowExceptionRateMultiple = FaultToleranceConfigManager.getLeastWindowExceptionRateMultiple(appName);
    for (InvocationStat invocationStat : invocationStats) {
        MeasureResultDetail measureResultDetail = null;
        InvocationStatDimension statDimension = invocationStat.getDimension();
        long windowCount = invocationStat.getInvokeCount();
        long invocationLeastWindowCount = getInvocationLeastWindowCount(invocationStat, ProviderInfoWeightManager.getWeight(statDimension.getProviderInfo()), leastWindowCount);
        if (averageExceptionRate == -1) {
            measureResultDetail = new MeasureResultDetail(statDimension, MeasureState.IGNORE);
        } else {
            if (invocationLeastWindowCount != -1 && windowCount >= invocationLeastWindowCount) {
                double windowExceptionRate = invocationStat.getExceptionRate();
                if (averageExceptionRate == 0) {
                    measureResultDetail = new MeasureResultDetail(statDimension, MeasureState.HEALTH);
                } else {
                    double windowExceptionRateMultiple = CalculateUtils.divide(windowExceptionRate, averageExceptionRate);
                    measureResultDetail = windowExceptionRateMultiple >= leastWindowExceptionRateMultiple ? new MeasureResultDetail(statDimension, MeasureState.ABNORMAL) : new MeasureResultDetail(statDimension, MeasureState.HEALTH);
                }
                measureResultDetail.setAbnormalRate(windowExceptionRate);
                measureResultDetail.setAverageAbnormalRate(averageExceptionRate);
                measureResultDetail.setLeastAbnormalRateMultiple(leastWindowExceptionRateMultiple);
            } else {
                measureResultDetail = new MeasureResultDetail(statDimension, MeasureState.IGNORE);
            }
        }
        measureResultDetail.setWindowCount(windowCount);
        measureResultDetail.setTimeWindow(timeWindow);
        measureResultDetail.setLeastWindowCount(invocationLeastWindowCount);
        measureResult.addMeasureDetail(measureResultDetail);
    }
    logMeasureResult(measureResult, timeWindow, leastWindowCount, averageExceptionRate, leastWindowExceptionRateMultiple);
    InvocationStatFactory.updateInvocationStats(invocationStats);
    return measureResult;
}
Also used : MeasureResult(com.alipay.sofa.rpc.client.aft.MeasureResult) InvocationStat(com.alipay.sofa.rpc.client.aft.InvocationStat) InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension) MeasureResultDetail(com.alipay.sofa.rpc.client.aft.MeasureResultDetail)

Aggregations

InvocationStat (com.alipay.sofa.rpc.client.aft.InvocationStat)1 InvocationStatDimension (com.alipay.sofa.rpc.client.aft.InvocationStatDimension)1 MeasureResult (com.alipay.sofa.rpc.client.aft.MeasureResult)1 MeasureResultDetail (com.alipay.sofa.rpc.client.aft.MeasureResultDetail)1