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

Bootstrap/restore bandwidth limit #4059

Merged
merged 21 commits into from
Jun 20, 2023
Merged

Conversation

Ben-PH
Copy link
Contributor

@Ben-PH Ben-PH commented Jun 8, 2023

  • document all added functions
  • try in sandbox /simulation/labnet
  • unit tests on the added/changed features
    • make tests compile
    • make tests pass
  • add logs allowing easy debugging in case the changes caused problems
  • if the API has changed, update the API specification

🤖 Generated by Copilot at c71d8d6

Summary

🚀🛠️🧪

This pull request adds bandwidth limiting to the bootstrap client and server using the stream_limiter crate. It changes the type of the max_bytes_read_write field in the bootstrap config structs and files from f64 to u64, and updates the tests and port numbers accordingly.

To limit the bootstrap bandwidth use
We wrap the TcpStream with a fuse
We change the config type
And fix some tests that hype
The stream_limiter crate we introduce

Walkthrough

@Ben-PH Ben-PH changed the base branch from main to testnet_24 June 8, 2023 19:42
@Ben-PH Ben-PH self-assigned this Jun 8, 2023
@Ben-PH Ben-PH added the bootstrap Issues related to the bootstrap label Jun 8, 2023
massa-bootstrap/src/bindings/client.rs Outdated Show resolved Hide resolved
massa-bootstrap/src/bindings/client.rs Outdated Show resolved Hide resolved
massa-bootstrap/src/bindings/server.rs Outdated Show resolved Hide resolved
massa-bootstrap/src/client.rs Outdated Show resolved Hide resolved
massa-bootstrap/src/client.rs Outdated Show resolved Hide resolved
massa-bootstrap/src/server.rs Outdated Show resolved Hide resolved
massa-bootstrap/src/tests/binders.rs Outdated Show resolved Hide resolved
@@ -179,7 +179,7 @@ fn stop_with_controller_still_exists() {
let mut config1 = ProtocolConfig::default();
config1
.listeners
.insert("127.0.0.1:8081".parse().unwrap(), TransportType::Tcp);
.insert("127.0.0.1:8083".parse().unwrap(), TransportType::Tcp);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This provided a fix locally, but fix doesn't work in CI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...apparently it does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...this is weird. last time I looked at this page, the CI had passed.

@Ben-PH Ben-PH requested a review from AurelienFT June 8, 2023 21:21
@Ben-PH Ben-PH marked this pull request as ready for review June 8, 2023 21:21
@Ben-PH Ben-PH requested a review from litchipi June 9, 2023 10:02
@litchipi
Copy link
Contributor

litchipi commented Jun 9, 2023

Note that for now stream_limiter is considered broken.
I'm working on fixing it (it fails when it comes to TcpStream limiting), but please do not merge this once everything is validated to be OK

@litchipi
Copy link
Contributor

After massalabs/stream_limiter#13 is merged, and a release created, you'll be able to update the dependency on it so we can have a working test setup :-)

@Ben-PH Ben-PH added the blocked Issues that can't be done for now. label Jun 13, 2023
@litchipi
Copy link
Contributor

@Ben-PH You can now update stream_limiter to version 3.0.0 as the fix is finished

@Ben-PH Ben-PH removed the blocked Issues that can't be done for now. label Jun 15, 2023
@Ben-PH Ben-PH added the blocked Issues that can't be done for now. label Jun 16, 2023
@Ben-PH Ben-PH mentioned this pull request Jun 16, 2023
15 tasks
@Ben-PH Ben-PH removed the blocked Issues that can't be done for now. label Jun 19, 2023
cfg: BootstrapClientConfig,
limit: Option<u64>,
) -> Self {
// A 1s window breaks anything requiring a 1s window
Copy link
Contributor

Choose a reason for hiding this comment

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

With the latest versions, you should be able to specify a bigger window version.

The limits will be divided to more granular values until an accepted threshold of rate is reached
(See https://github.com/massalabs/stream_limiter/blob/main/src/lib.rs#L47)

So you should be able to specify your rate without needing to divide and set the timewindow as millis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

max_bytes_read_write: _limit,
thread_count,
max_datastore_key_length,
randomness_size_bytes,
consensus_bootstrap_part_size,
write_error_timeout,
} = cfg;

// A 1s window breaks anything requiring a 1s window
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.unwrap();
let dur = before.elapsed();
assert!(dbg!(dur) > Duration::from_secs(10));
assert!(dur < Duration::from_millis(11_500));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that this kind of assert may fail sometimes

That's because TCP packets are bound to 64Kb per packet, so even if we allow more data to be sent, we'll have to do multiple read.
Even without any limiting (sleep) occuring, this means that it's possible to be still slower than the rate limit set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That could possibly explain why CI is failing on windows.

Any suggestions for limit setup in tests, and how much of an assert window to provide?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the window to 1s, with a 1:2 window to bucket ratio. I'll see how that behaves in CI, then adjust the assert window accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sorry the thing I said is outdated, normally the overhead isn't strong enough to make the whole thing fail (that was a bug on a version that I forgot I fixed)
You should be fine with this assert now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah. Got things working with windows, but now mac is failing. takes about 20s. I'll account for mac, and assuming that's good, and green across the board, ill hit merge. Thanks!

Copy link
Contributor

@litchipi litchipi left a comment

Choose a reason for hiding this comment

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

Let's try to make the CI green before merging

@Ben-PH Ben-PH merged commit 0f97b3c into testnet_24 Jun 20, 2023
@Ben-PH Ben-PH mentioned this pull request Jun 22, 2023
@AurelienFT AurelienFT deleted the bootstrap/restore-bandwidth-limit branch October 23, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bootstrap Issues related to the bootstrap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants