php熔断机制实现,RPC实现原理之核⼼技术-限流熔断熔断降级源码
DegradeRule.passCheck⽅法:@Override
public boolean passCheck(Context context, DefaultNode node, int acquireCount, args) {
if (()) {
return false;
}
ClusterNode clusterNode = Resource());
if (clusterNode == null) {
return true;
}
if (grade == RuleConstant.DEGRADE_GRADE_RT) {
/
/ 按平均响应时间降级
double rt = clusterNode.avgRt();
if (rt < unt) {
passCount.set(0);
return true;
}
// Sentinel will degrade the service only if count exceeds.
// 超出最⼤RT时间进⾏降级
if (passCount.incrementAndGet() < RT_MAX_EXCEED_N) {
return true;
}
} else if (grade == RuleConstant.DEGRADE_GRADE_EXCEPTION_RATIO) {
// 按照异常⽐例降级
double exception = ptionQps();
double success = clusterNode.successQps();
double total = alQps();
// if total qps less than RT_MAX_EXCEED_N, pass.
if (total < RT_MAX_EXCEED_N) {
return true;
}
double realSuccess = success - exception;
if (realSuccess <= 0 && exception < RT_MAX_EXCEED_N) {
return true;
}
degradeif (exception / success < count) {
return true;
}
} else if (grade == RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) { // 按照异常数降级
double exception = alException();
if (exception < count) {
return true;
}
}
if (cutpareAndSet(false, true)) {
ResetTask resetTask = new ResetTask(this);
// 设定重置时间窗调度任务
pool.schedule(resetTask, timeWindow, TimeUnit.SECONDS);
}
return false;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。