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

Refactor the bandwidth logging to be less magic #1670

Merged
merged 5 commits into from
Jul 27, 2020

Conversation

tomaka
Copy link
Member

@tomaka tomaka commented Jul 21, 2020

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 the BandwidthLogging 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 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.

src/bandwidth.rs Outdated
Comment on lines 135 to 136
download: Atomic<u64>,
upload: Atomic<u64>,

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Contributor

@romanb romanb left a 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?

src/bandwidth.rs Outdated Show resolved Hide resolved
src/bandwidth.rs Outdated Show resolved Hide resolved
src/bandwidth.rs Outdated Show resolved Hide resolved
src/bandwidth.rs Outdated Show resolved Hide resolved
@tomaka
Copy link
Member Author

tomaka commented Jul 22, 2020

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 libp2p-quic and not something pressing.

@romanb romanb merged commit 8a08f72 into libp2p:master Jul 27, 2020
@tomaka tomaka deleted the rework-bandwidth-logging branch July 27, 2020 09:08
hrxi added a commit to hrxi/rust-libp2p that referenced this pull request May 11, 2022
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`.
thomaseizinger pushed a commit that referenced this pull request May 12, 2022
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`.
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.

3 participants