Spring Cloud 断路器
来源:互联网 发布:苹果mac os x系统下载 编辑:程序博客网 时间:2024/04/27 19:23
1. Smaphore策略
参数配置:
/** * execution SEMAPHORE */ @HystrixCommand( groupKey = "Semaphore test", //hystrix dashboard 中 ThreadPool的名字 commandKey = "Semaphore test", //hystrix dashboard 中 Circuit的名字,如果使用SEMAPHORE策略,dashboard里面没有ThreadPool显示 commandProperties = { @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE"), @HystrixProperty(name = "execution.isolation.semaphore.maxConcurrentRequests", value = "2") //default 10,当隔离策略使用信号量的时候,当并发请求数达到此值,后续请求将被拒绝 } ) public String helloSemaphore(){ return "ok"; }
Apache Bench测试:
ab -n 100 -c 3 -t 20 http://localhost:9000/ribbon/consumer/hystrix/semaphore
2.Thread策略
参数配置:
/** * circuitBreaker 断路器 */ @HystrixCommand( fallbackMethod = "helloFallback", groupKey = "custom CircuitBreaker test", //hystrix dashboard 中 ThreadPool的名字 commandKey = "custom CircuitBreaker test", //hystrix dashboard 中 Circuit的名字 commandProperties = { // @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000"), //default 1000 @HystrixProperty(name = "circuitBreaker.enabled", value = "true"), //default true, 当服务命令请求失败,是否开启断路器来跟踪此服务健康指标和熔断服务请求 @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "20"), //default 20, 设置在滚动时间窗中,断路器熔断的最小请求数,在时间窗内(默认10s)内收到了19个请求,即使这19个请求都失败,也不断路(熔断器不打开) @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "3000"), //default 5000, 设置在断路器打开后的休眠时间窗,休眠时间窗结束后,断路器为“半开”状态 @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "20"), //default 50, 设置断路器打开的错误百分比条件。在滚动时间窗内,请求数超过requestVolumeThreshold,如果错误请求数>50%,断路器打开 @HystrixProperty(name = "circuitBreaker.forceOpen", value = "false"), //default false, 强制打开断路器 @HystrixProperty(name = "circuitBreaker.forceClosed", value = "false") //default false, 强制关闭断路器,如果forceOpen=true,此属性无效 }, threadPoolProperties = { @HystrixProperty(name = "coreSize", value = "10"), //default 10,执行命令线程池核心线程数 @HystrixProperty(name = "maxQueueSize", value = "15"), //default -1,线程池等待队列的最大大小,-1使用SynchronousQueue,否则使用LinkedBlockingQueue,不能动态刷新此配置 @HystrixProperty(name = "queueSizeRejectionThreshold", value = "17"), //default 5, 队列拒绝阈值,LinkedBlockingQueue maxSize不能动态修改,通过此属性补充 @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "10000"), //default 10s,线程池滚动时间窗,统计线程池指标时间度量 @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "10") //default 10, 线程池滚动时间窗被划分的“桶”的数量 } ) public String helloCircuitBreaker(){ long start = System.currentTimeMillis(); String result = restTemplate.getForEntity("http://HELLO-SERVICE/hello", String.class).getBody(); System.out.println("spend time: " + (System.currentTimeMillis() - start) + "ms"); return result; }
Apache Bench测试:
ab -n 10 -c 5 -t 20 http://localhost:9000/ribbon/consumer/hystrix/circuitBreaker
阅读全文
0 0
- Spring Cloud 之断路器
- Spring Cloud 断路器
- spring cloud: Hystrix断路器(熔断器)
- spring cloud: Hystrix断路器(熔断器)
- Spring Cloud 断路器Hystrix实战
- spring cloud学习笔记-断路器
- Spring Cloud 中的断路器 hystrix
- spring cloud: Hystrix断路器(熔断器)
- Spring Cloud FeignClient 断路器配置
- spring cloud: Hystrix断路器(熔断器)
- Spring Cloud中的断路器Hystrix
- spring cloud FeignClient fallback 断路器
- Spring Cloud 配置服务消费者和断路器
- spring cloud学习(五)断路器 Hystrix
- Spring Cloud系列三 之 Hystrix断路器
- Spring Cloud微服架构之断路器
- Spring Cloud 学习之旅 --- 断路器
- [bigdata-110] spring-cloud-06 Hystrix断路器
- this关键字----应用
- VMware Workstation 共享磁盘和Linux的UDEV使用
- oracle参数文件
- cscope选项
- form表单submit提交后台无反应、前端不报错
- Spring Cloud 断路器
- 网页后门工具laudanum
- 基于jfinal-weixin-1.7的微信公众号开发代码分析
- android 命令行获取root权限
- SSM框架Spring+SpringMVC+MyBatis——详细整合教程
- C# Winform文件上传服务器
- React Route打开新窗口出现Not Found
- linux 常用命令笔记
- 插入排序及其优化