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 ClientOptions.cpuRateLimit #2151

Merged
merged 5 commits into from
Mar 18, 2022
Merged

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Mar 17, 2022

Adding an option to limit the amount of CPU consumed by smoldot.

Warp syncing a long chain such as Kusama can use a lot of CPU for up to 10-15 seconds, and we'd rather not have a web page or the substrate-connect extension use up an entire CPU for this long, as it tends to cause systems to freeze.
After this change is merged and published, I'd cap the CPU to 50% in substrate-connect.

Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

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

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        +393 ┊ <smoldot_light_wasm::cpu_rate_limiter::CpuRateLimiter<T> as core::future::future::Future>::poll::h129a42f3c0b4c4de
        -201 ┊ smoldot_light_wasm::init::init::{{closure}}::{{closure}}::{{closure}}::h4aab948761687b79
        +201 ┊ smoldot_light_wasm::init::init::{{closure}}::{{closure}}::{{closure}}::hd7e19adb8045aaaf
         +75 ┊ core::ptr::drop_in_place<smoldot_light_wasm::cpu_rate_limiter::CpuRateLimiter<core::future::from_generator::GenFuture<smoldot_light_wasm::init::init<alloc::vec::Vec<futures_util::abortable::AbortHandle>,smoldot_light_wasm::platform::Platform>::{{closure}}>>>::h37d1b6eac73ce75b
         -73 ┊ <smoldot_light_wasm::platform::Platform as smoldot_light_base::Platform>::sleep_until::h004d951d4576a059
         +73 ┊ smoldot_light_wasm::timers::Delay::new_at::h1ceafbbf91a77047
         -64 ┊ core::ptr::drop_in_place<core::future::from_generator::GenFuture<smoldot_light_wasm::init::init<alloc::vec::Vec<futures_util::abortable::AbortHandle>,smoldot_light_wasm::platform::Platform>::{{closure}}>>::h5e689831c5355336
         -54 ┊ smoldot_light_wasm::init::init::{{closure}}::{{closure}}::{{closure}}::hb190226bc087101c
         +54 ┊ smoldot_light_wasm::init::init::{{closure}}::{{closure}}::{{closure}}::hef748433d472c231
         +51 ┊ init
         +42 ┊ smoldot_light_wasm::init::init::{{closure}}::h3739f99282e16c21
         -42 ┊ smoldot_light_wasm::init::init::{{closure}}::h6d729e1d79d0771f
         -11 ┊ type[24]: (i32, i32, i32, i32, i32, i32, i32) -> i32
         +11 ┊ type[25]: (i32, i32, i32, i32, i32, i32, i32) -> i32
          -9 ┊ type[25]: (i32, i32, i32, i32, i32) -> i32
          +9 ┊ type[26]: (i32, i32, i32, i32, i32) -> i32
          +9 ┊ type[39]: (i32, i64, i64, i32, i32) -> i32
          +9 ┊ type[40]: (i32, i64, i32, i32, i32) -> i32
          -9 ┊ type[40]: (i32, i64, i64, i32, i32) -> i32
          -9 ┊ type[41]: (i32, i64, i32, i32, i32) -> i32
          +3 ┊ ... and 34 more.
        +602 ┊ Σ [54 Total Rows]

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

// We add a small zero-cost shim to ensure at compile time that this is indeed the case.
fn enforce_fused<T: futures::future::FusedFuture>(_: &T) {}
enforce_fused(&this.prevent_poll_until);
match Future::poll(this.prevent_poll_until.as_mut(), cx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpik: since we're interested in only one arm

Suggested change
match Future::poll(this.prevent_poll_until.as_mut(), cx) {
if let Poll::Pending = Future::poll(this.prevent_poll_until.as_mut(), cx) {

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Mar 18, 2022
@mergify mergify bot merged commit 9177f07 into paritytech:main Mar 18, 2022
@tomaka tomaka deleted the cpu-rate-limit branch March 18, 2022 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants