概述 SystemSlot 处于 StatisticSlot 节点后面,如果开启系统状态校验,则会校验整个系统总的qps/rt/cup利用率/负载。
解析 继承关系
entry() 方法 entry() 方法中调用了 SystemRuleManager 的 checkSystem 方法。
1 2 3 4 5 6 @Override public void entry (Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, boolean prioritized, Object... args) throws Throwable { SystemRuleManager.checkSystem(resourceWrapper); fireEntry(context, resourceWrapper, node, count, prioritized, args); }
SystemRuleManager ** 几个属性
1 2 3 4 5 private static volatile double highestCpuUsage = Double.MAX_VALUE;private static volatile double qps = Double.MAX_VALUE;private static volatile long maxRt = Long.MAX_VALUE;private static volatile long maxThread = Long.MAX_VALUE;private static AtomicBoolean checkSystemStatus = new AtomicBoolean(false );
checkSystem 方法
是否开启checkSystemStatus,如果false就结束,不然就继续;
只有类型是IN,则结束,不然继续;
如果当前系统QPS大于设置的最大QPS,则抛出 SystemBlockException;
如果当前系统rt大于设置的最大rt,则抛出 SystemBlockException;
如果当前系统的负载大于设置的最大负载,则抛出 SystemBlockException;
如果当前系统的cpu利用率大于设置的最大值,则抛出 SystemBlockException;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 public static void checkSystem (ResourceWrapper resourceWrapper) throws BlockException { if (!checkSystemStatus.get()) { return ; } if (resourceWrapper.getType() != EntryType.IN) { return ; } double currentQps = Constants.ENTRY_NODE == null ? 0.0 : Constants.ENTRY_NODE.successQps(); if (currentQps > qps) { throw new SystemBlockException(resourceWrapper.getName(), "qps" ); } int currentThread = Constants.ENTRY_NODE == null ? 0 : Constants.ENTRY_NODE.curThreadNum(); if (currentThread > maxThread) { throw new SystemBlockException(resourceWrapper.getName(), "thread" ); } double rt = Constants.ENTRY_NODE == null ? 0 : Constants.ENTRY_NODE.avgRt(); if (rt > maxRt) { throw new SystemBlockException(resourceWrapper.getName(), "rt" ); } if (highestSystemLoadIsSet && getCurrentSystemAvgLoad() > highestSystemLoad) { if (!checkBbr(currentThread)) { throw new SystemBlockException(resourceWrapper.getName(), "load" ); } } if (highestCpuUsageIsSet && getCurrentCpuUsage() > highestCpuUsage) { if (!checkBbr(currentThread)) { throw new SystemBlockException(resourceWrapper.getName(), "cpu" ); } } }
exit() 方法 1 2 3 4 @Override public void exit (Context context, ResourceWrapper resourceWrapper, int count, Object... args) { fireExit(context, resourceWrapper, count, args); }