1. 打开hystrix
2. 【soul-bootstrap】添加hystrix依赖
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-plugin-hystrix</artifactId>
<version>${project.version}</version>
</dependency>
3. 配置hystrix选折器
4. 配置hystrix规则
为了测试 将最小请求数和并发请求数调为1
Hystrix支持信号量和线程隔离模式
Hystrix 的线程池隔离针对不同的资源分别创建不同的线程池,不同服务调用都发生在不同的线程池中,在线程池排队、超时等阻塞情况时可以快速失败,并可以提供 fallback 机制。
Hystrix 的信号量隔离限制对某个资源调用的并发数。这样的隔离非常轻量级,仅限制对某个资源调用的并发数,而不是显式地去创建线程池,所以 overhead 比较小,但是效果不错,也支持超时失败。
5. 启动【soul-admin】、【soul-bootstrap】和要访问的服务
6. 使用压测进行访问
wrk -t10 -c100 -d10s http://localhost:9195/http/order/findById\?id\=1
Running 10s test @ http://localhost:9195/http/order/findById?id=1
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 16.96ms 38.01ms 376.59ms 94.42%
Req/Sec 1.15k 336.87 2.03k 69.39%
113011 requests in 10.03s, 11.96MB read
Requests/sec: 11272.62
Transfer/sec: 1.19MB
7. 尝试访问失败(发生熔断)
curl http://localhost:9195/http/order/findById\?id\=1
{"code":-103,"message":"Service invocation exception, or no result is returned!","data":null}%