-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature:自适应重试控制策略 #270
base: dev
Are you sure you want to change the base?
feature:自适应重试控制策略 #270
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #270 +/- ##
==========================================
- Coverage 95.87% 95.39% -0.49%
==========================================
Files 69 72 +3
Lines 3566 3692 +126
==========================================
+ Hits 3419 3522 +103
- Misses 114 131 +17
- Partials 33 39 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
count := atomic.AddUint64(&s.reqCount, 1) | ||
count = count % (uint64(64) * uint64(len(s.ringBuffer))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我属实没看懂这个地方是做啥的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里计算真实长度
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你不需要计算什么长度,直接用固定的初始化好的比特位个数。
count := atomic.AddUint64(&s.reqCount, 1) | ||
count = count % (uint64(64) * uint64(len(s.ringBuffer))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你不需要计算什么长度,直接用固定的初始化好的比特位个数。
idx := count >> 6 | ||
bitPos := count & 63 | ||
for { | ||
old := atomic.LoadUint64(&s.ringBuffer[idx]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要 CAS,直接设置,省时省力,性能优秀
if res.ringBufferLen <= 0 { | ||
return nil, fmt.Errorf("ekit: 无效的滑动窗口长度 [%d]", res.ringBufferLen) | ||
|
||
} | ||
|
||
if res.threshold <= 0 { | ||
return nil, errs.NewErrInvalidThresholdValue(res.threshold) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
药医不死病,佛渡有缘人,删了这些检查。
我现在想着,之前有一些 API 设计得太保姆了,没必要。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删去之后,你就不需要返回 error 了
return failCount | ||
} | ||
|
||
func NewAdaptiveTimeoutRetryStrategy(strategy Strategy, opts ...Option) (*AdaptiveTimeoutRetryStrategy, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
强制要求传入三个参数:strategy, cnt, threshold
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注意这里 cnt 如果不是 8 的整数倍,我们就用大于 cnt 的能用字节来表达的数字。而后 threshold 则是不变。
例如说用户传入 cnt= 15,那么我们的应该用 16 = 2个字节。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要传入 cnt 的话,还是不可避免要 count = count % (uint64(64) * uint64(cnt))) 的计算
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这是啥东西?你算这个干啥?你只是要找出大于 cnt 的8的整数倍,作为切片的长度。
strategy Strategy // 基础重试策略 | ||
threshold int // 超时比率阈值 (单位:比特数量) | ||
ringBuffer []uint64 // 比特环(滑动窗口存储超时信息) | ||
reqCount uint64 // 请求数量 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删掉。你不需要这个字段。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
相当于刚开始的时候就有 N 个请求了,并且这些请求都没超时。
No description provided.