Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

optimize: reduce the waiting time for starting dfget server #1088

Merged
merged 1 commit into from
Nov 25, 2019

Conversation

lowzj
Copy link
Member

@lowzj lowzj commented Nov 20, 2019

Signed-off-by: lowzj [email protected]

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@lowzj lowzj force-pushed the optimize-server-start branch from baa7538 to 8573a82 Compare November 20, 2019 13:46
@@ -42,7 +42,8 @@ type Downloader interface {
// the given timeout duration.
func DoDownloadTimeout(downloader Downloader, timeout time.Duration) error {
if timeout <= 0 {
logrus.Warnf("invalid download timeout(%.3fs)", timeout.Seconds())
logrus.Debugf("invalid download timeout(%.3fs), use default:(%.3fs)",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to use Warnf, since it is a useful message for operators.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's better to use WARN level.
But it makes user confused because that this invalid value is set by dfget not specified by user. I will open another pr to fix it.

func waitForStartup(result chan error, p2pPtr *unsafe.Pointer) (err error) {
ticker := time.NewTicker(5 * time.Millisecond)
defer ticker.Stop()
timeout := time.After(233 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

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

why to use this value 233 * time.Millisecond. How about declaring it a const value?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not a multiple of 5, is a prime number. And it's enough for retry to start a http server. 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, it's weird for 233ms. Maybe other contributors will feel the same way. Could you please add a comment for it? In addition, how about declaring it a const value as @allencloud said?

Copy link
Member Author

Choose a reason for hiding this comment

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

why is 233 ms, not others?

It's weird for us because of unfamiliarity, but it's really the one. There are many things in the world that are unexpected. I have already commented on this function to describe why this number jumps out by itself. It jumps into my brain, and I have to write it down.

why not declare it as a const value

I think that maybe it's unnecessary to declare it as a const value. The code here can explain its meaning by a very simple and clear way by itself: it's the timeout of waiting for starting server. Just like the variable ticker with 5ms above. It will lose its meaning when it appears in any other places. And the important thing is that it's very hard to come up with a name of the constant value which can explain itself without context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, Man!

@lowzj lowzj force-pushed the optimize-server-start branch from 8573a82 to 633bf7c Compare November 21, 2019 09:25
@codecov-io
Copy link

Codecov Report

Merging #1088 into master will increase coverage by 0.04%.
The diff coverage is 96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1088      +/-   ##
==========================================
+ Coverage   47.28%   47.32%   +0.04%     
==========================================
  Files         118      118              
  Lines        7225     7235      +10     
==========================================
+ Hits         3416     3424       +8     
- Misses       3540     3541       +1     
- Partials      269      270       +1
Impacted Files Coverage Δ
dfget/core/uploader/peer_server_executor.go 86.95% <100%> (+0.38%) ⬆️
dfget/core/uploader/uploader.go 88.03% <95.65%> (-0.04%) ⬇️
supernode/daemon/mgr/scheduler/manager.go 21.91% <0%> (-0.69%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04f0ffe...633bf7c. Read the comment docs.

@starnop
Copy link
Contributor

starnop commented Nov 25, 2019

LGTM.

@starnop starnop merged commit 72b98ba into dragonflyoss:master Nov 25, 2019
@lowzj lowzj deleted the optimize-server-start branch November 25, 2019 11:37
starnop added a commit to starnop/Dragonfly that referenced this pull request Nov 27, 2019
optimize: reduce the waiting time for starting dfget server
inoc603 pushed a commit to inoc603/Dragonfly that referenced this pull request Dec 23, 2019
optimize: reduce the waiting time for starting dfget server
sungjunyoung pushed a commit to sungjunyoung/Dragonfly that referenced this pull request May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants