-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## sentinel限流机制源码解析 | ||
|
||
sentinel实现了三种限流策略,针对QPS和并发线程数进行限制。这三种策略分别是: | ||
|
||
* 直接拒绝(默认) | ||
* 匀速排队 | ||
* warm up 冷启动 | ||
|
||
本文分别对3种策略的实现原理,结合源代码进行分析。 | ||
|
||
### 匀速排队策略 | ||
|
||
什么是匀速排队呢?举个例子,假设我们希望某类请求的QPS为10,即1s内通过10个请求,相当于每个请求平均占用100ms。匀速策略其实就是“平均策略”,限制每个请求之间相隔100ms,这样就能保证请求匀速通过并满足10的QPS。 | ||
|
||
请求调用时,sentinel会基于当前统计,计算下一个请求应该通过的时间, 并判断当前请求能否通过或是否需要进行等待。有的业务场景对请求的实时性有一定要求,我们可以为请求设置超时时间,如果需要等待的时间超过了超时时间,则直接拒绝掉。 | ||
|
||
|
||
|
||
|
||
|