use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension 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;
}
use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.
the class ServiceHorizontalMeasureStrategy method removeMeasureModel.
@Override
public MeasureModel removeMeasureModel(InvocationStat invocationStat) {
InvocationStatDimension statDimension = invocationStat.getDimension();
MeasureModel measureModel = appServiceMeasureModels.get(statDimension.getDimensionKey());
if (measureModel != null) {
measureModel.removeInvocationStat(invocationStat);
}
return measureModel;
}
use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.
the class ServiceHorizontalMeasureStrategy method buildMeasureModel.
/**
* 如果该Invocation不属于一个MeasureModel,那么创建一个MeasureModel。并返回该MeasureModel。
* 如果该Invocation属于一个MeasureModel,那么将该Invocation加入到该MeasureModel中。返回null。
*
* @param invocationStat InvocationStat
* @return MeasureModel
*/
@Override
public MeasureModel buildMeasureModel(InvocationStat invocationStat) {
InvocationStatDimension statDimension = invocationStat.getDimension();
String key = statDimension.getDimensionKey();
MeasureModel measureModel = appServiceMeasureModels.get(key);
if (measureModel == null) {
measureModel = new MeasureModel(statDimension.getAppName(), statDimension.getService());
MeasureModel oldMeasureModel = appServiceMeasureModels.putIfAbsent(key, measureModel);
if (oldMeasureModel == null) {
measureModel.addInvocationStat(invocationStat);
return measureModel;
} else {
oldMeasureModel.addInvocationStat(invocationStat);
return null;
}
} else {
measureModel.addInvocationStat(invocationStat);
return null;
}
}
use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.
the class ServiceHorizontalMeasureStrategy method getInvocationLeastWindowCount.
/**
* 根据Invocation的实际权重计算该Invocation的实际最小窗口调用次数 如果目标地址原始权重为0,或者地址已经被剔除则返回-1。
*
* @param invocationStat InvocationStat
* @param weight weight
* @param leastWindowCount original least Window count
* @return leastWindowCount
*/
private long getInvocationLeastWindowCount(InvocationStat invocationStat, Integer weight, long leastWindowCount) {
InvocationStatDimension statDimension = invocationStat.getDimension();
Integer originWeight = statDimension.getOriginWeight();
if (originWeight == 0) {
LOGGER.errorWithApp(statDimension.getAppName(), LogCodes.getLog(LogCodes.ERROR_ORIGIN_WEIGHT_ZERO, statDimension.getService(), statDimension.getIp()));
return -1;
} else if (weight == null) {
// 如果地址还未被调控过或者已经恢复。
return leastWindowCount;
} else if (weight == -1) {
// 如果地址被剔除
return -1;
}
double rate = CalculateUtils.divide(weight, originWeight);
long invocationLeastWindowCount = CalculateUtils.multiply(leastWindowCount, rate);
return invocationLeastWindowCount < LEGAL_LEAST_WINDOW_COUNT ? LEGAL_LEAST_WINDOW_COUNT : invocationLeastWindowCount;
}
use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.
the class ServiceHorizontalRegulationStrategy method removeFromDegradeList.
@Override
public void removeFromDegradeList(MeasureResultDetail measureResultDetail) {
if (measureResultDetail.isRecoveredOriginWeight()) {
InvocationStatDimension statDimension = measureResultDetail.getInvocationStatDimension();
getDegradeProviders(statDimension.getDimensionKey()).remove(statDimension.getIp());
}
}
Aggregations