-
Notifications
You must be signed in to change notification settings - Fork 960
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
Refactor the bandwidth logging to be less magic #1670
Conversation
src/bandwidth.rs
Outdated
download: Atomic<u64>, | ||
upload: Atomic<u64>, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Should this go out as a new libp2p
minor release on merge (since it contains breaking changes) or just be included with the next release eventually?
I'm not sure I understand your question, but this change is mostly in preparation for |
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Replace `atomic::Atomic<u64>` by `std::sync::atomic:AtomicU64`. The original motivation of using `atomic::Atomic<u64>` instead of `std`'s version in libp2p#1670 was the following: > I used the atomic crate and an Atomic<u64> because the AtomicU64 type > isn't available on all architectures. The atomic crate automatically > falls back to using a Mutex on platforms that don't support AtomicU64. This argumentation is moot because the crate directly depends on `libp2p-core` which also uses `AtomicU64`.
Replace `atomic::Atomic<u64>` by `std::sync::atomic:AtomicU64`. The original motivation of using `atomic::Atomic<u64>` instead of `std`'s version in #1670 was the following: > I used the atomic crate and an Atomic<u64> because the AtomicU64 type > isn't available on all architectures. The atomic crate automatically > falls back to using a Mutex on platforms that don't support AtomicU64. This argumentation is moot because the crate directly depends on `libp2p-core` which also uses `AtomicU64`.
At the moment, the bandwidth logging system in libp2p automatically tries to perform a 5-seconds average of the number of bytes that are transferred through its sockets.
This PR completely reworks that system and instead makes the bandwidth logging system only count and report the number of bytes. The user can later grab this number of bytes and perform their own 5-seconds-average if they need to.
This reason for this change is that users wouldn't be able to plug the
BandwidthLogging
struct on a QUIC transport. In order to make it possible for users to measure the bandwidth of QUIC connections, we would have to duplicate the averaging-algorithm of theBandwidthLogging
inside of the QUIC transport itself.I think it is an overall better approach to simply measure the number of bytes. It removes a
Mutex
, and is generally less magic than performing our own calculation.I used the
atomic
crate and anAtomic<u64>
because theAtomicU64
type isn't available on all architectures. Theatomic
crate automatically falls back to using aMutex
on platforms that don't supportAtomicU64
.