sentinel之三种熔断降级情况的验证

熔断降级是指当资源处于不稳定的情况下,在接下来的时间窗口之内,对该资源的调用都自动熔断(默认行为是抛出DegradeException)。
通常用三种方式来衡量资源是否处于稳定的状态:

  • 平均响应时间 (DEGRADE_GRADE_RT):当资源的平均响应时间超过阈值(DegradeRule 中的 count,以 ms 为单位)之后,资源进入准降级状态。接下来如果持续进入 5 个请求,它们的 RT 都持续超过这个阈值,那么在接下的时间窗口(DegradeRule 中的 timeWindow,以 s 为单位)之内,对这个方法的调用都会自动地返回(抛出 DegradeException)。

  • 异常比例 (DEGRADE_GRADE_EXCEPTION_RATIO):当资源的每秒异常总数占通过量的比值超过阈值(DegradeRule 中的 count)之后,资源进入降级状态,即在接下的时间窗口(DegradeRule 中的 timeWindow,以 s 为单位)之内,对这个方法的调用都会自动地返回。异常比率的阈值范围是 [0.0, 1.0],代表 0% - 100%。

  • 异常数 (DEGRADE_GRADE_EXCEPTION_COUNT):当资源近 1 分钟的异常数目超过阈值之后会进行熔断。

注意:为了统计异常比例或异常数,需要通过 Tracer.trace(ex) 记录业务异常。
下面对这三种情况做简单的验证

  • 导入Maven依赖
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-core</artifactId>
    <version>1.3.0-GA</version>
</dependency>

点击这里可查询最新的sentinel-core版本
1、验证平均响应时间

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.util.TimeUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 降级是在资源处于不稳定状态时使用的,这些资源将在下一个定义的时间窗口内降级。
 * 有三种方法衡量资源是否稳定:
 * 平均响应时间 (DEGRADE_GRADE_RT):当资源的平均响应时间超过阈值(DegradeRule 中的 count,以 ms 为单位)之后,
 * 资源进入准降级状态。接下来如果持续进入 5 个请求,它们的 RT 都持续超过这个阈值,
 * 那么在接下的时间窗口(DegradeRule 中的 timeWindow,以 s 为单位)之内,
 * 对这个方法的调用都会自动地返回(抛出 DegradeException)
 * **异常比率,见 {@link ExceptionRatioDegradeDemo}.
 * **异常统计,见 {@link ExceptionCountDegradeDemo}.
 */
public class RtDegradeDemo {

    private static final String KEY = "平均响应时间";

    private static AtomicInteger pass = new AtomicInteger();
    private static AtomicInteger block = new AtomicInteger();
    private static AtomicInteger total = new AtomicInteger();

    private static volatile boolean stop = false;
    private static final int threadCount = 100;
    private static int seconds = 60;

    public static void main(String[] args) throws Exception {
        tick();
        initDegradeRule();// 设置资源降级规则

        for (int i = 0; i < threadCount; i++) {
            Thread entryThread = new Thread(new Runnable() {
                int j = 0;

                @Override
                public void run() {
                    while (true) {
                        Entry entry = null;
                        try {
                            TimeUnit.MILLISECONDS.sleep(5);
                            entry = SphU.entry(KEY);
                            // 令牌已获得
                            pass.incrementAndGet();// 先+1,然后在返回值,相当于++i
                            // sleep 600 ms, as rt
                            TimeUnit.MILLISECONDS.sleep(600);
                        } catch (Exception e) {
                            // System.out.println("异常:"+e);
                            // 降级计数
                            block.incrementAndGet();// 先+1,然后在返回值,相当于++i
                        } finally {
                            // 记录总数
                            total.incrementAndGet();// 先+1,然后在返回值,相当于++i
                            if (entry != null) {
                                entry.exit();
                            }
                        }
                    }
                }

            });
            entryThread.setName("working-thread");
            entryThread.start();
        }
    }

    /**
     * 当资源的平均响应时间超过阈值(DegradeRule 中的 count,以 ms 为单位)之后,资源进入准降级状态。
     * 接下来如果持续进入 5 个请求,它们的 RT 都持续超过这个阈值,
     * 那么在接下的时间窗口(DegradeRule 中的 timeWindow,以 s 为单位)之内,
     * 对这个方法的调用都会自动地返回(抛出 DegradeException)。
     */
    private static void initDegradeRule() {
        List<DegradeRule> rules = new ArrayList<DegradeRule>();
        DegradeRule rule = new DegradeRule();
        rule.setResource(KEY);// 设置资源名,资源名是限流规则的作用对象
        rule.setCount(10);// 设置平均响应时间阈值为10ms
        rule.setGrade(RuleConstant.DEGRADE_GRADE_RT);// 设置降级模式,根据平均响应时间降级
        rule.setTimeWindow(10);// 设置降级的时间,以s为单位
        rules.add(rule);
        DegradeRuleManager.loadRules(rules);
    }

    private static void tick() {
        Thread timer = new Thread(new TimerTask());
        timer.setName("sentinel-timer-task");
        timer.start();
    }

    static class TimerTask implements Runnable {
        @Override
        public void run() {
            long start = System.currentTimeMillis();
            System.out.println("统计开始......");
            long oldTotal = 0;
            long oldPass = 0;
            long oldBlock = 0;

            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String nowTime = "";

            while (!stop) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                }

                long globalTotal = total.get();
                long oneSecondTotal = globalTotal - oldTotal;
                oldTotal = globalTotal;

                long globalPass = pass.get();
                long oneSecondPass = globalPass - oldPass;
                oldPass = globalPass;

                long globalBlock = block.get();
                long oneSecondBlock = globalBlock - oldBlock;
                oldBlock = globalBlock;

                nowTime = formatter.format(new java.util.Date(TimeUtil.currentTimeMillis()));
                System.out.println(nowTime + ", total:" + oneSecondTotal + ", pass:" + oneSecondPass + ", block:" + oneSecondBlock);

                if (seconds-- <= 0) {
                    stop = true;
                }
            }

            long cost = System.currentTimeMillis() - start;
            System.out.println("耗时:" + cost + " ms");
            System.out.println("总计数:" + total.get() + ", 通过数:" + pass.get() + ", 降级数:" + block.get());
            System.out.println("统计结束!");
            System.exit(0);
        }
    }

}

执行结果如下:

统计开始......
2018-12-10 16:42:26, total:2387, pass:104, block:2288
2018-12-10 16:42:27, total:15446, pass:0, block:15442
2018-12-10 16:42:28, total:17507, pass:0, block:17506
2018-12-10 16:42:29, total:17939, pass:0, block:17940
2018-12-10 16:42:30, total:17731, pass:0, block:17730
2018-12-10 16:42:31, total:17800, pass:0, block:17800
2018-12-10 16:42:32, total:17973, pass:0, block:17975
2018-12-10 16:42:33, total:17814, pass:0, block:17812
2018-12-10 16:42:34, total:18000, pass:0, block:18000
2018-12-10 16:42:35, total:17832, pass:0, block:17832
2018-12-10 16:42:36, total:14944, pass:100, block:14944
2018-12-10 16:42:37, total:9700, pass:4, block:9600
2018-12-10 16:42:38, total:18063, pass:0, block:18059
2018-12-10 16:42:39, total:17828, pass:0, block:17828
2018-12-10 16:42:40, total:18000, pass:0, block:18000
2018-12-10 16:42:41, total:17800, pass:0, block:17800
2018-12-10 16:42:42, total:17900, pass:0, block:17900
2018-12-10 16:42:43, total:17800, pass:0, block:17800
2018-12-10 16:42:44, total:17890, pass:0, block:17890
2018-12-10 16:42:45, total:17908, pass:0, block:17908
2018-12-10 16:42:46, total:17868, pass:0, block:17871
2018-12-10 16:42:47, total:7830, pass:100, block:7827
2018-12-10 16:42:48, total:16856, pass:4, block:16752
2018-12-10 16:42:49, total:17963, pass:0, block:17965
2018-12-10 16:42:50, total:17541, pass:0, block:17539
2018-12-10 16:42:51, total:17600, pass:0, block:17600
2018-12-10 16:42:52, total:17770, pass:0, block:17770
2018-12-10 16:42:53, total:17400, pass:0, block:17400
2018-12-10 16:42:54, total:17753, pass:0, block:17755
2018-12-10 16:42:55, total:17642, pass:0, block:17640
2018-12-10 16:42:56, total:17796, pass:0, block:17796
2018-12-10 16:42:57, total:17884, pass:0, block:17887
2018-12-10 16:42:58, total:6872, pass:104, block:6769
2018-12-10 16:42:59, total:17720, pass:0, block:17716
2018-12-10 16:43:00, total:17889, pass:0, block:17892
2018-12-10 16:43:01, total:17611, pass:0, block:17608
2018-12-10 16:43:02, total:17851, pass:0, block:17851
2018-12-10 16:43:03, total:17900, pass:0, block:17900
2018-12-10 16:43:04, total:17800, pass:0, block:17800
2018-12-10 16:43:05, total:17800, pass:0, block:17800
2018-12-10 16:43:06, total:17900, pass:0, block:17900
2018-12-10 16:43:07, total:17800, pass:0, block:17800
2018-12-10 16:43:08, total:11600, pass:100, block:11600
2018-12-10 16:43:09, total:12876, pass:4, block:12772
2018-12-10 16:43:10, total:17896, pass:0, block:17896
2018-12-10 16:43:11, total:17981, pass:0, block:17983
2018-12-10 16:43:12, total:17819, pass:0, block:17817
2018-12-10 16:43:13, total:17800, pass:0, block:17800
2018-12-10 16:43:14, total:17976, pass:0, block:17977
2018-12-10 16:43:15, total:17707, pass:0, block:17708
2018-12-10 16:43:16, total:17881, pass:0, block:17883
2018-12-10 16:43:17, total:17832, pass:0, block:17828
2018-12-10 16:43:18, total:17900, pass:0, block:17900
2018-12-10 16:43:19, total:6974, pass:104, block:6892
2018-12-10 16:43:20, total:17497, pass:0, block:17476
2018-12-10 16:43:21, total:17666, pass:0, block:17665
2018-12-10 16:43:22, total:18000, pass:0, block:18000
2018-12-10 16:43:23, total:17900, pass:0, block:17900
2018-12-10 16:43:24, total:17800, pass:0, block:17800
2018-12-10 16:43:25, total:17894, pass:0, block:17894
2018-12-10 16:43:26, total:17765, pass:0, block:17765
耗时:61080 ms
总计数:1014072, 通过数:624, 降级数:1013448
统计结束!

Process finished with exit code 0

2、验证异常比例

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.util.TimeUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 降级是在资源处于不稳定状态时使用的,这些资源将在下一个定义的时间窗口内降级。
 * 有三种方法衡量资源是否稳定:
 * 异常比率:当异常计数/秒与成功的比率qps大于或等于阈值时,对资源的访问将被阻塞在即将到来的时间窗口。
 * **异常统计,见 {@link ExceptionCountDegradeDemo}.
 * **平均响应时间, 见 {@link RtDegradeDemo}.
 */
public class ExceptionRatioDegradeDemo {
    private static final String KEY = "异常比率";

    private static AtomicInteger total = new AtomicInteger();
    private static AtomicInteger pass = new AtomicInteger();
    private static AtomicInteger block = new AtomicInteger();
    private static AtomicInteger bizException = new AtomicInteger();

    private static volatile boolean stop = false;
    private static final int threadCount = 1;
    private static int seconds = 60 + 40;

    public static void main(String[] args) throws Exception {
        tick();
        initDegradeRule();// 设置资源降级规则

        for (int i = 0; i < threadCount; i++) {
            Thread entryThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    int count = 0;
                    while (true) {
                        count++;
                        Entry entry = null;
                        try {
                            Thread.sleep(20);
                            entry = SphU.entry(KEY);
                            // 获得令牌表示通过
                            pass.addAndGet(1);// 先+n,然后在返回值
                            if (count % 2 == 0) {
                                // 业务代码引发异常
                                throw new RuntimeException("throw runtime exception");
                            }
                        } catch (BlockException e) {
                            // 降级计数
                            block.addAndGet(1);// 先+n,然后在返回值
                        } catch (Throwable t) {
                            // 记录业务异常
                            bizException.incrementAndGet();// 先+1,然后在返回值,相当于++i
                            // 为了统计异常比例或异常数,需要通过 Tracer.trace(ex) 记录业务异常。
                            Tracer.trace(t);
                        } finally {
                            // 记录总数
                            total.addAndGet(1);// 先+n,然后在返回值
                            if (entry != null) {
                                entry.exit();
                            }
                        }
                    }
                }

            });
            entryThread.setName("working-thread");
            entryThread.start();
        }

    }

    /**
     * 当资源的每秒异常总数占通过量的比值超过阈值(DegradeRule 中的 count)之后,
     * 资源进入降级状态,即在接下的时间窗口(DegradeRule 中的 timeWindow,以 s 为单位)之内,对这个方法的调用都会自动地返回。
     * 异常比率的阈值范围是 [0.0, 1.0],代表 0% - 100%。
     */
    private static void initDegradeRule() {
        List<DegradeRule> rules = new ArrayList<DegradeRule>();
        DegradeRule rule = new DegradeRule();
        rule.setResource(KEY);// 设置资源名,资源名是限流规则的作用对象
        // 将限制异常比率设置为0.1
        rule.setCount(0.5);// 异常比率的阈值范围是 [0.0, 1.0],代表 0% - 100%。
        rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_RATIO);// 设置降级模式,根据异常比率降级
        rule.setTimeWindow(10);// 设置降级的时间,以s为单位
        rules.add(rule);
        DegradeRuleManager.loadRules(rules);
    }

    private static void tick() {
        Thread timer = new Thread(new TimerTask());
        timer.setName("sentinel-timer-task");
        timer.start();
    }

    static class TimerTask implements Runnable {
        @Override
        public void run() {
            long start = System.currentTimeMillis();
            System.out.println("统计开始......");
            long oldTotal = 0;
            long oldPass = 0;
            long oldBlock = 0;
            long oldBizException = 0;

            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String nowTime = "";

            while (!stop) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                }
                long globalTotal = total.get();
                long oneSecondTotal = globalTotal - oldTotal;
                oldTotal = globalTotal;

                long globalPass = pass.get();
                long oneSecondPass = globalPass - oldPass;
                oldPass = globalPass;

                long globalBlock = block.get();
                long oneSecondBlock = globalBlock - oldBlock;
                oldBlock = globalBlock;

                long globalBizException = bizException.get();
                long oneSecondBizException = globalBizException - oldBizException;
                oldBizException = globalBizException;

                nowTime = formatter.format(new java.util.Date(TimeUtil.currentTimeMillis()));
                System.out.println(nowTime + ", oneSecondTotal:" + oneSecondTotal
                        + ", oneSecondPass:" + oneSecondPass
                        + ", oneSecondBlock:" + oneSecondBlock
                        + ", oneSecondBizException:" + oneSecondBizException);
                if (seconds-- <= 0) {
                    stop = true;
                }
            }
            long cost = System.currentTimeMillis() - start;
            System.out.println("耗时:" + cost + " ms");
            System.out.println("总计数:" + total.get() + ", 通过数:" + pass.get()
                    + ", 降级数:" + block.get() + ", 业务异常数:" + bizException.get());
            System.out.println("统计结束!");
            System.exit(0);
        }
    }
}

执行结果如下:

统计开始......
2018-12-10 17:02:04, oneSecondTotal:37, oneSecondPass:6, oneSecondBlock:31, oneSecondBizException:3
2018-12-10 17:02:05, oneSecondTotal:47, oneSecondPass:0, oneSecondBlock:47, oneSecondBizException:0
2018-12-10 17:02:06, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:07, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:08, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:09, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:10, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:11, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:12, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:13, oneSecondTotal:47, oneSecondPass:0, oneSecondBlock:47, oneSecondBizException:0
2018-12-10 17:02:14, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
2018-12-10 17:02:15, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:16, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:17, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:18, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:19, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:20, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:21, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:22, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:23, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:24, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
2018-12-10 17:02:25, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:26, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:27, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:28, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:29, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:30, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:31, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:32, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:33, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:34, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
2018-12-10 17:02:35, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:36, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:37, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:38, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:39, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:40, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:41, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:42, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:43, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:44, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
2018-12-10 17:02:45, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:46, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:47, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:48, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:49, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:50, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:51, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:52, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:53, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:54, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
2018-12-10 17:02:55, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:56, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:57, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:02:58, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:02:59, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:00, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:01, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:02, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:03, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:04, oneSecondTotal:49, oneSecondPass:2, oneSecondBlock:47, oneSecondBizException:1
2018-12-10 17:03:05, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:06, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:07, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:08, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:09, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:10, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:11, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:12, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:13, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:14, oneSecondTotal:49, oneSecondPass:2, oneSecondBlock:47, oneSecondBizException:1
2018-12-10 17:03:15, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:16, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:17, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:18, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:19, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:20, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:21, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:22, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:23, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:24, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
2018-12-10 17:03:25, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:26, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:27, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:28, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:29, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:30, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:31, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:32, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:33, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:34, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
2018-12-10 17:03:35, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:36, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:03:37, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:38, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:39, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:40, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:41, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:42, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:43, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:03:44, oneSecondTotal:48, oneSecondPass:2, oneSecondBlock:46, oneSecondBizException:1
耗时:101096 ms
总计数:4865, 通过数:26, 降级数:4839, 业务异常数:13
统计结束!

Process finished with exit code 0

3、验证异常数

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.util.TimeUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 降级是在资源处于不稳定状态时使用的,这些资源将在下一个定义的时间窗口内降级。
 * 有三种方法衡量资源是否稳定:
 * 异常计数:当异常计数在最后60秒内大于或等于阈值时,对资源的访问将被阻塞在时间窗口。
 * **异常比率,见{@link ExceptionRatioDegradeDemo}。
 * **平均响应时间,见{@link RtDegradeDemo}。
 * 注意:当通过{@link RuleConstant#DEGRADE_GRADE_EXCEPTION_COUNT}进行降级时,时间窗口少于60秒将无法正常工作。
 * 因为异常计数是按分钟求和的,所以在较短的时间窗口过后,仍然可以满足降级条件。
 */
public class ExceptionCountDegradeDemo {
    private static final String KEY = "异常计数";

    private static AtomicInteger total = new AtomicInteger();
    private static AtomicInteger pass = new AtomicInteger();
    private static AtomicInteger block = new AtomicInteger();
    private static AtomicInteger bizException = new AtomicInteger();

    private static volatile boolean stop = false;
    private static final int threadCount = 1;
    private static int seconds = 60 + 40;

    public static void main(String[] args) throws Exception {
        tick();
        initDegradeRule();// 设置资源降级规则

        for (int i = 0; i < threadCount; i++) {
            Thread entryThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    int count = 0;
                    while (true) {
                        count++;
                        Entry entry = null;
                        try {
                            Thread.sleep(20);
                            entry = SphU.entry(KEY);
                            // 获得令牌表示通过
                            pass.addAndGet(1);// 先+n,然后在返回值
                            if (count % 2 == 0) {
                                // 业务代码引发异常
                                throw new RuntimeException("throw runtime exception");
                            }
                        } catch (BlockException e) {
                            // 降级计数
                            block.addAndGet(1);// 先+n,然后在返回值
                        } catch (Throwable t) {
                            // 记录业务异常
                            bizException.incrementAndGet();// 先+1,然后在返回值,相当于++i
                            // 为了统计异常比例或异常数,需要通过 Tracer.trace(ex) 记录业务异常。
                            Tracer.trace(t);
                        } finally {
                            // 记录总数
                            total.addAndGet(1);// 先+n,然后在返回值
                            if (entry != null) {
                                entry.exit();
                            }
                        }
                    }
                }

            });
            entryThread.setName("working-thread");
            entryThread.start();
        }

    }

    /**
     * 当资源近 1 分钟的异常数目超过阈值之后会进行熔断
     */
    private static void initDegradeRule() {
        List<DegradeRule> rules = new ArrayList<DegradeRule>();
        DegradeRule rule = new DegradeRule();
        rule.setResource(KEY);// 设置资源名,资源名是限流规则的作用对象
        rule.setCount(800);// 设置限流阈值,将异常计数限制为800
        rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT);// 设置降级模式,根据异常计数降级
        /*
         * 当通过{@link RuleConstant#DEGRADE_GRADE_EXCEPTION_COUNT},进行降级时,时间窗口少于60秒将无法正常工作。
         * 因为异常计数是按分钟求和的,所以在较短的时间窗口过后,仍然可以满足降级条件。
         * 如在10秒内已经达到降级阈值,且加上setTimeWindow设置的降级时间仍未超过一分钟的,
         * 则在一分钟内仍然满足降级条件,setTimeWindow设置的降级时间不生效,需等待满一分钟时间后才能恢复服务。
         */
        rule.setTimeWindow(10);// 设置降级的时间,以s为单位
        rules.add(rule);
        DegradeRuleManager.loadRules(rules);
    }

    private static void tick() {
        Thread timer = new Thread(new TimerTask());
        timer.setName("sentinel-timer-task");
        timer.start();
    }

    static class TimerTask implements Runnable {
        @Override
        public void run() {
            long start = System.currentTimeMillis();
            System.out.println("统计开始......");
            long oldTotal = 0;
            long oldPass = 0;
            long oldBlock = 0;
            long oldBizException = 0;

            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String nowTime = "";

            while (!stop) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                }
                long globalTotal = total.get();
                long oneSecondTotal = globalTotal - oldTotal;
                oldTotal = globalTotal;

                long globalPass = pass.get();
                long oneSecondPass = globalPass - oldPass;
                oldPass = globalPass;

                long globalBlock = block.get();
                long oneSecondBlock = globalBlock - oldBlock;
                oldBlock = globalBlock;

                long globalBizException = bizException.get();
                long oneSecondBizException = globalBizException - oldBizException;
                oldBizException = globalBizException;

                nowTime = formatter.format(new java.util.Date(TimeUtil.currentTimeMillis()));
                System.out.println(nowTime + ", oneSecondTotal:" + oneSecondTotal
                        + ", oneSecondPass:" + oneSecondPass
                        + ", oneSecondBlock:" + oneSecondBlock
                        + ", oneSecondBizException:" + oneSecondBizException);

                if (seconds-- <= 0) {
                    stop = true;
                }
            }
            long cost = System.currentTimeMillis() - start;
            System.out.println("耗时:" + cost + " ms");
            System.out.println("总计数:" + total.get() + ", 通过数:" + pass.get()
                    + ", 降级数:" + block.get() + ", 业务异常数:" + bizException.get());
            System.out.println("统计结束!");
            System.exit(0);
        }
    }
}

执行结果如下:

统计开始......
2018-12-10 17:06:00, oneSecondTotal:37, oneSecondPass:37, oneSecondBlock:0, oneSecondBizException:18
2018-12-10 17:06:01, oneSecondTotal:47, oneSecondPass:47, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:02, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:03, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:04, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:05, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:06, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:07, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:08, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:09, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:10, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:06:11, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:12, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:13, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:14, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:15, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:16, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:17, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:18, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:19, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:06:20, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:21, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:22, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:23, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:24, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:25, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:06:26, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:27, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:28, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:29, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:30, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:31, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:32, oneSecondTotal:47, oneSecondPass:47, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:06:33, oneSecondTotal:47, oneSecondPass:22, oneSecondBlock:25, oneSecondBizException:11
2018-12-10 17:06:34, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:35, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:36, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:37, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:38, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:39, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:40, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:41, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:42, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:43, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:44, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:45, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:46, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:47, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:48, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:49, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:50, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:51, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:52, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:53, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:54, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:55, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:56, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:06:57, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:58, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:06:59, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:07:00, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:07:01, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:07:02, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:07:03, oneSecondTotal:47, oneSecondPass:25, oneSecondBlock:22, oneSecondBizException:12
2018-12-10 17:07:04, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:05, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:06, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:07, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:08, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:09, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:10, oneSecondTotal:47, oneSecondPass:47, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:11, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:12, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:13, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:14, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:15, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:07:16, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:17, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:18, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:19, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:20, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:07:21, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:22, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:23, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:24, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:25, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:07:26, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:27, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:28, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:29, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:30, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:31, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:07:32, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:33, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:34, oneSecondTotal:48, oneSecondPass:48, oneSecondBlock:0, oneSecondBizException:24
2018-12-10 17:07:35, oneSecondTotal:49, oneSecondPass:49, oneSecondBlock:0, oneSecondBizException:25
2018-12-10 17:07:36, oneSecondTotal:48, oneSecondPass:30, oneSecondBlock:18, oneSecondBizException:15
2018-12-10 17:07:37, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:07:38, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
2018-12-10 17:07:39, oneSecondTotal:49, oneSecondPass:0, oneSecondBlock:49, oneSecondBizException:0
2018-12-10 17:07:40, oneSecondTotal:48, oneSecondPass:0, oneSecondBlock:48, oneSecondBizException:0
耗时:101110 ms
总计数:4862, 通过数:3200, 降级数:1662, 业务异常数:1600
统计结束!

Process finished with exit code 0

以上结果均符合预期

– END –

猜你喜欢

转载自blog.csdn.net/Ramboll/article/details/84942779