Skip to content
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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

Stone-afk
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Dec 15, 2024

Codecov Report

Attention: Patch coverage is 93.97590% with 5 lines in your changes missing coverage. Please review.

Project coverage is 95.39%. Comparing base (44dea05) to head (5cbb328).
Report is 6 commits behind head on dev.

Files with missing lines Patch % Lines
retry/adaptive.go 92.85% 4 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

retry/adaptive.go Outdated Show resolved Hide resolved
retry/adaptive.go Outdated Show resolved Hide resolved
Comment on lines +72 to +73
count := atomic.AddUint64(&s.reqCount, 1)
count = count % (uint64(64) * uint64(len(s.ringBuffer)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我属实没看懂这个地方是做啥的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里计算真实长度

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你不需要计算什么长度,直接用固定的初始化好的比特位个数。

retry/adaptive.go Outdated Show resolved Hide resolved
Comment on lines +72 to +73
count := atomic.AddUint64(&s.reqCount, 1)
count = count % (uint64(64) * uint64(len(s.ringBuffer)))
Copy link
Contributor

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要 CAS,直接设置,省时省力,性能优秀

Comment on lines +109 to +116
if res.ringBufferLen <= 0 {
return nil, fmt.Errorf("ekit: 无效的滑动窗口长度 [%d]", res.ringBufferLen)

}

if res.threshold <= 0 {
return nil, errs.NewErrInvalidThresholdValue(res.threshold)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

药医不死病,佛渡有缘人,删了这些检查。
我现在想着,之前有一些 API 设计得太保姆了,没必要。

Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

强制要求传入三个参数:strategy, cnt, threshold

Copy link
Contributor

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个字节。

Copy link
Contributor Author

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))) 的计算

Copy link
Contributor

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 // 请求数量
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删掉。你不需要这个字段。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相当于刚开始的时候就有 N 个请求了,并且这些请求都没超时。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants