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

fix: qps is not correct #221

Merged
merged 1 commit into from
Oct 19, 2023
Merged

fix: qps is not correct #221

merged 1 commit into from
Oct 19, 2023

Conversation

ii2day
Copy link
Collaborator

@ii2day ii2day commented Sep 22, 2023

fix #95

原方法:每个并发协程平均分配请求,这样会导致,请求数量大于期望的请求数量,影响结果,如期望发送 15 个请求,10 个并发协程执行,当完成 10 个请求后,剩余 5 个请求被 5 个协程分配,但剩下的 5 个协程没有被分配到 依然会去请求,影响期望结果。

现方法:将请求的数量放入一个 channel 中,每个并发协程去channel 中拿请求的许可,拿到许可才进行请求。

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Merging #221 (1139931) into main (49beec5) will increase coverage by 0.35%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #221      +/-   ##
==========================================
+ Coverage   39.16%   39.52%   +0.35%     
==========================================
  Files           8        8              
  Lines         526      544      +18     
==========================================
+ Hits          206      215       +9     
- Misses        315      323       +8     
- Partials        5        6       +1     
Flag Coverage Δ
unittests 39.52% <77.77%> (+0.35%) ⬆️

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

Files Coverage Δ
pkg/loadRequest/loadDns/dns.go 90.90% <100.00%> (-1.20%) ⬇️
pkg/loadRequest/loadDns/dns_reporter.go 87.09% <ø> (ø)
pkg/loadRequest/loadDns/dns_requester.go 87.58% <76.92%> (-5.04%) ⬇️

@weizhoublue
Copy link
Collaborator

我记得当初有要求完成 在 server 应用端 验证 请求数,这个用例 没验证出 这大bug 么 ?如果没有,请闭环 用例

@ii2day ii2day force-pushed the pr/ii2day/concurrency branch 2 times, most recently from a1b1708 to a7768a9 Compare September 25, 2023 01:47
@ii2day
Copy link
Collaborator Author

ii2day commented Sep 25, 2023

我记得当初有要求完成 在 server 应用端 验证 请求数,这个用例 没验证出 这大bug 么 ?如果没有,请闭环 用例

之前的用例是实际请求与期望请求差值在 10%就可以,现在已经更改为实际与期望相等才可通过。

@weizhoublue
Copy link
Collaborator

pr 描述中 , “如期望发送 15 个请求,10 个并发协程执行,当完成 10 个请求后,剩余 5 个请求被 5 个协程分配,但剩下的 5 个协程没有被分配到 依然会去请求,影响期望结果”

而 之前e2e 偏差容忍是 10%, 那 PR 描述 不准确,还是 E2E 有 bug 没测试出来

@ii2day
Copy link
Collaborator Author

ii2day commented Sep 27, 2023

pr 描述中 , “如期望发送 15 个请求,10 个并发协程执行,当完成 10 个请求后,剩余 5 个请求被 5 个协程分配,但剩下的 5 个协程没有被分配到 依然会去请求,影响期望结果”

而 之前e2e 偏差容忍是 10%, 那 PR 描述 不准确,还是 E2E 有 bug 没测试出来

之前的e2e 设置的 qps 以及并发量正好偏差在 10%以内所以用例通过了,现在已经将e2e 用例更改为固定期望数值了。

@weizhoublue
Copy link
Collaborator

pr 描述中 , “如期望发送 15 个请求,10 个并发协程执行,当完成 10 个请求后,剩余 5 个请求被 5 个协程分配,但剩下的 5 个协程没有被分配到 依然会去请求,影响期望结果”
而 之前e2e 偏差容忍是 10%, 那 PR 描述 不准确,还是 E2E 有 bug 没测试出来

之前的e2e 设置的 qps 以及并发量正好偏差在 10%以内所以用例通过了,现在已经将e2e 用例更改为固定期望数值了。

如果是用绝对值 比较,是否 可能会出现一些 边际效应,例如超时时间的偏差,导致实际多一个或者少一个请求,导致 用例 时过时不过

@ii2day
Copy link
Collaborator Author

ii2day commented Oct 9, 2023

pr 描述中 , “如期望发送 15 个请求,10 个并发协程执行,当完成 10 个请求后,剩余 5 个请求被 5 个协程分配,但剩下的 5 个协程没有被分配到 依然会去请求,影响期望结果”
而 之前e2e 偏差容忍是 10%, 那 PR 描述 不准确,还是 E2E 有 bug 没测试出来

之前的e2e 设置的 qps 以及并发量正好偏差在 10%以内所以用例通过了,现在已经将e2e 用例更改为固定期望数值了。

如果是用绝对值 比较,是否 可能会出现一些 边际效应,例如超时时间的偏差,导致实际多一个或者少一个请求,导致 用例 时过时不过

client 是根据 qps 来进行发送请求,超时时间内会发送完所有请求,所有请求返回完毕才会结束,若因为超时原因失败,那是否可以考虑是 server 不满足我的任务需求,请求是协程在做,不会阻塞,除非超时时间设置的不合理,才会导致少发请求,但我们在 webhook 中对超时时间进行了检查,不会出现这种情况。

@weizhoublue
Copy link
Collaborator

client 是根据 qps 来进行发送请求,超时时间内会发送完所有请求,所有请求返回完毕才会结束
----- 如果最后一个请求 刚好 卡在 超时的 0.001 秒 错过了呢 ?

@weizhoublue
Copy link
Collaborator

本pr是否需要改进

@ii2day
Copy link
Collaborator Author

ii2day commented Oct 12, 2023

本pr是否需要改进

需要改进,等复用daemonset 的需求搞完,弄此pr

@ii2day ii2day force-pushed the pr/ii2day/concurrency branch 3 times, most recently from 8d0370d to e14ccf8 Compare October 17, 2023 08:32
@ii2day
Copy link
Collaborator Author

ii2day commented Oct 17, 2023

本pr是否需要改进

已改进完成,通过根据 qps 设置定时器发送 channel 控制请求发送,拿到 token 的并发协程才去请求,未拿到 token 的协程继续等待,用例请求误差容忍改为5%。

@@ -64,6 +67,7 @@ type Work struct {
initOnce sync.Once
results chan *result
stopCh chan struct{}
runCh chan struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

-> qosTokenBucket

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

b.Stop()
return
case <-ticker.C:
b.runCh <- struct{}{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

投放的 debug 日志

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@ii2day ii2day force-pushed the pr/ii2day/concurrency branch 6 times, most recently from 70bea9f to 174a717 Compare October 17, 2023 11:46
b.Stop()
return
case <-ticker.C:
b.Logger.Sugar().Debugf("request token channel len: %d", len(b.qosTokenBucket))
Copy link
Collaborator

Choose a reason for hiding this comment

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

需要 len > 0 有错误日志

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

select {
case <-c:
// Reach request duration stop request
b.Logger.Sugar().Debugf("request finish remaining number of tokens len: %d", len(b.qosTokenBucket))
Copy link
Collaborator

@weizhoublue weizhoublue Oct 18, 2023

Choose a reason for hiding this comment

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

需要 len > 0 有错误日志 ,且任务失败

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@ii2day ii2day force-pushed the pr/ii2day/concurrency branch 5 times, most recently from aa0488a to 868c9d6 Compare October 19, 2023 03:37
Signed-off-by: ii2day <ji.li@daocloud.io>
@weizhoublue weizhoublue changed the title fix conflicts between concurrency and request counts fix: qps is not correct Oct 19, 2023
@weizhoublue weizhoublue merged commit 1aaf685 into main Oct 19, 2023
23 of 24 checks passed
@weizhoublue weizhoublue deleted the pr/ii2day/concurrency branch October 19, 2023 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

当期望请求数小于默认的并发量时,测试数据出现异常
2 participants