ratelimiter是一款限流插件,限流的级别可以精确到接口级,参数级。
使用Redis的令牌桶算法
1. 启动【soul-admin】和【soul-bootstrap】
2.登录管理界面,开启rate-limiter插件
3. 配置用户测试的选择器【ratelimiter-test】
4. 配置规则【ratelimiter-test-rule】
5. 启动【soul-examples-http】
6. 访问 /http/order/findById
curl http://localhost:9195/http/order/findById\?id\=1
{"id":"1","name":"hello world findById"}%
7. 使用压测工具进行熔断, 存在错误
wrk -t10 -c100 -d9s http://localhost:9195/http/order/findById\?id\=1
Running 9s test @ http://localhost:9195/http/order/findById?id=1
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 35.29ms 45.26ms 260.33ms 84.69%
Req/Sec 553.21 175.91 1.38k 69.67%
49611 requests in 9.01s, 8.10MB read
Non-2xx or 3xx responses: 48928
Requests/sec: 5503.50
Transfer/sec: 0.90MB
8. 再次访问 /http/order/findById,发生了熔断
curl http://localhost:9195/http/order/findById\?id\=1
{"code":429,"message":"You have been restricted, please try again later!","data":null}%