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

Add methods to clear stats #10

Merged
merged 12 commits into from
Nov 1, 2019
Merged

Add methods to clear stats #10

merged 12 commits into from
Nov 1, 2019

Conversation

kpp
Copy link
Contributor

@kpp kpp commented Oct 31, 2019

No description provided.

@kpp kpp changed the title WIP: Add methods to clear stats Add methods to clear stats Oct 31, 2019
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Thanks!

meter.go Outdated Show resolved Hide resolved
meter.go Show resolved Hide resolved
meter.go Outdated Show resolved Hide resolved
@kpp kpp changed the title Add methods to clear stats WIP: Add methods to clear stats Oct 31, 2019
@kpp kpp changed the title WIP: Add methods to clear stats Add methods to clear stats Oct 31, 2019
@kpp kpp requested a review from Stebalien October 31, 2019 23:12
kpp and others added 5 commits November 1, 2019 02:19
1. Handle `registered` inside the main loop. This way we can avoid atomics.
2. Don't start calculating bandwidth for newly active meters until they've been
active for a round. This:
  1. Ensures we only write to the snapshot from within the main loop.
  2. Gives us a better estimated bandwidth usage.
1. The last update is when we last saw activity. We don't need to update it when
we reset the meter.
2. Defer isn't _quite_ as fast as it could be.
sweeper.go Outdated Show resolved Hide resolved
meter.go Outdated Show resolved Hide resolved
meter.go Outdated Show resolved Hide resolved
@Stebalien
Copy link
Member

@kpp I needed to so some experimentation so it was simpler to make changes directly than to leave comments in a review. Do my changes LGTY?

@kpp
Copy link
Contributor Author

kpp commented Nov 1, 2019

Your solution looks even better than mine. LGTM

@kpp
Copy link
Contributor Author

kpp commented Nov 1, 2019

Unfortunately your solution does not pass tests from go-libp2p-core/metrics. See https://github.com/libp2p/go-libp2p-core/pull/71/files and play with it.

~/ipfs/go-libp2p-core/metrics$ go test
--- FAIL: TestBandwidthCounter (5.00s)
    bandwidth_test.go:111: expected 2000.000000 (±140.000000), got 3999.427234
    bandwidth_test.go:112: expected 1000.000000 (±70.000000), got 1999.713617
    bandwidth_test.go:111: expected 2000.000000 (±140.000000), got 3999.427234
    bandwidth_test.go:112: expected 1000.000000 (±70.000000), got 1999.713617
    bandwidth_test.go:111: expected 2000.000000 (±140.000000), got 3999.427234
...

Whereas mine works fine. Don't forget about replace in go.mod

@Stebalien
Copy link
Member

The issue is that this version starts tracking bandwidth one second later. I'll update those tests.

The previous attempt actually make the problem worse:

1. It didn't update the "last update" time.
2. It updated the accumulator but then didn't set the total. That meant that the
_next_ update would count the bandwidth from two time periods.

This change also reverts the changes to the test (the test was right, the code
was wrong).
@Stebalien
Copy link
Member

Actually, the issue is that I implemented this wrong, misdiagnosed why the test was failing, then broke the tests 🤦‍♂️. Fixed.

@Stebalien Stebalien merged commit c3e5539 into libp2p:master Nov 1, 2019
@kpp kpp deleted the clear_stat branch November 1, 2019 09:46
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.

2 participants