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

限速逻辑有问题 #109

Open
wy-ei opened this issue Aug 3, 2022 · 0 comments
Open

限速逻辑有问题 #109

wy-ei opened this issue Aug 3, 2022 · 0 comments

Comments

@wy-ei
Copy link

wy-ei commented Aug 3, 2022

在 speed.go 这个文件中,定义了一个 Qos 结构用于限速。其中启动了一个定时器,每秒往一个 chan 中放 qps 个 token。因为第一次放 token 是在一秒之后,这导致对某个 db 执行 VerifyAllKeyInfo 之前需要等待 1 秒,这大大拖慢了 check 的速度。

相关代码如下:

// limit qps
qos := common.StartQoS(conf.Opts.Qps)
for keyInfo := range allKeys {
    <-qos.Bucket
    p.verifier.VerifyOneGroupKeyInfo(keyInfo, conflictKey, &sourceClient, &targetClient)
} // for oneGroupKeys := range allKeys

func (q *Qos) timer() {
	for range time.NewTicker(1 * time.Second).C {
		if q.close {
			return
		}
		for i := 0; i < q.limit; i++ {
			select {
			case q.Bucket <- struct{}{}:
			default:
				// break if bucket if full
				break
			}
		}
	}
}

我考虑可以在启动 timer 的时候,就立刻扔 q.limit 个 token 到 q.Bucket 中。

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

No branches or pull requests

1 participant