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

configable budget for runtime #5775

Closed
wants to merge 3 commits into from
Closed

configable budget for runtime #5775

wants to merge 3 commits into from

Conversation

gftea
Copy link
Contributor

@gftea gftea commented Jun 7, 2023

addressing #5696
First experiment with configurable coop budget
Also create an example project for benchmarking

@github-actions github-actions bot added the R-loom Run loom tests on this PR label Jun 7, 2023
@gftea
Copy link
Contributor Author

gftea commented Jun 7, 2023

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-coop Module: tokio/coop labels Jun 8, 2023
coop-budget/Cargo.toml Outdated Show resolved Hide resolved
@gftea
Copy link
Contributor Author

gftea commented Jun 12, 2023

Hi,

I would like to breakdown the work into below plan

  1. this PR will add only configuration api on runtime builder
  2. will issue another PR for per task budget
  3. will create seperate project for use cases implementation for benchmarking, either inside or outside tokio repo, please suggest your preference. @Darksonn @carllerche @Noah-Kennedy

@gftea
Copy link
Contributor Author

gftea commented Jun 12, 2023

Summary of benchmark

After running a similar duration, we can see with budget=32, it has better latency performance according to 99.9% quantile, stdev and mean value

high priority with budget = 32

[src/client.rs:72] tag = "high priority client"
[src/client.rs:72] hist.len() = 428775
[src/client.rs:72] hist.min() = 0
[src/client.rs:72] hist.mean() = 321.4437572153228
[src/client.rs:72] hist.stdev() = 1093.6610468983138
[src/client.rs:72] hist.max() = 48671
[src/client.rs:72] hist.value_at_quantile(0.999) = 13919
[src/client.rs:72] tag = "high priority client"
[src/client.rs:72] hist.len() = 434070
[src/client.rs:72] hist.min() = 0
[src/client.rs:72] hist.mean() = 321.55305595871664
[src/client.rs:72] hist.stdev() = 1094.422093579727
[src/client.rs:72] hist.max() = 48671
[src/client.rs:72] hist.value_at_quantile(0.999) = 13911
[src/client.rs:72] tag = "high priority client"
[src/client.rs:72] hist.len() = 439395
[src/client.rs:72] hist.min() = 0
[src/client.rs:72] hist.mean() = 321.2118344541942
[src/client.rs:72] hist.stdev() = 1093.3720641192087
[src/client.rs:72] hist.max() = 48671
[src/client.rs:72] hist.value_at_quantile(0.999) = 13895

high priority with budget = 128

[src/client.rs:72] tag = "high priority client"
[src/client.rs:72] hist.len() = 426473
[src/client.rs:72] hist.min() = 0
[src/client.rs:72] hist.mean() = 496.84516722043395
[src/client.rs:72] hist.stdev() = 1387.013451650282
[src/client.rs:72] hist.max() = 62847
[src/client.rs:72] hist.value_at_quantile(0.999) = 15767
[src/client.rs:72] tag = "high priority client"
[src/client.rs:72] hist.len() = 431781
[src/client.rs:72] hist.min() = 0
[src/client.rs:72] hist.mean() = 494.767087945045
[src/client.rs:72] hist.stdev() = 1385.5939732739735
[src/client.rs:72] hist.max() = 62847
[src/client.rs:72] hist.value_at_quantile(0.999) = 15767
[src/client.rs:72] tag = "high priority client"
[src/client.rs:72] hist.len() = 437103
[src/client.rs:72] hist.min() = 0
[src/client.rs:72] hist.mean() = 492.5462785659203
[src/client.rs:72] hist.stdev() = 1383.6372255004694
[src/client.rs:72] hist.max() = 62847
[src/client.rs:72] hist.value_at_quantile(0.999) = 15767

machine

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   39 bits physical, 48 bits virtual
CPU(s):                          4
On-line CPU(s) list:             0-3
Thread(s) per core:              2
Core(s) per socket:              2
Socket(s):                       1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           140
Model name:                      11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Stepping:                        1
CPU MHz:                         2995.200
BogoMIPS:                        5990.40
Hypervisor vendor:               Microsoft
Virtualization type:             full
L1d cache:                       96 KiB
L1i cache:                       64 KiB
L2 cache:                        2.5 MiB
L3 cache:                        12 MiB

@Darksonn Darksonn changed the title configable budget for runtime #5696 configable budget for runtime Jun 12, 2023
tokio/src/runtime/coop.rs Outdated Show resolved Hide resolved
tokio/src/runtime/coop.rs Outdated Show resolved Hide resolved
Comment on lines 78 to 83
pub(crate) fn budget<R>(f: impl FnOnce() -> R) -> R {
with_budget(Budget::initial(), f)
with_budget(
context::get_init_budget().unwrap_or_else(|_| Budget::initial()),
f,
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This introduces an extra thread-local access on every poll. @carllerche Thoughts? I think you said that you were working on reducing them.

Copy link
Member

Choose a reason for hiding this comment

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

We should be removing TLS calls in the hot path at this point. It should be possible to build this without any more TLS lookups.

I'm in the middle of a big scheduler refactor. It will be easier to make this change after the refactor lands. Ideally in 2-3 weeks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For stable api, get_init_budget() return value directly instead of accessing the TLS, see below

pub(super) fn get_init_budget() -> Result<coop::Budget, AccessError> {
    #[cfg(not(tokio_unstable))]
    {
        Ok(coop::Budget::default())
    }

    #[cfg(tokio_unstable)]
    {
        CONTEXT.try_with(|ctx| ctx.initial_budget.get())
    }
}

@Darksonn
Copy link
Contributor

I'm going to close this, because we don't want to add additional uses of the thread-local at this time.

@Darksonn Darksonn closed this Oct 22, 2023
@gftea
Copy link
Contributor Author

gftea commented Oct 22, 2023

I'm going to close this, because we don't want to add additional uses of the thread-local at this time.

@Darksonn , may I know what is plan forward, would we consider to work on this after some factors are done?

@Darksonn
Copy link
Contributor

If you want to start working on this again with a different approach, then I'm open to that. You no longer need to wait for Carl's work to finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-coop Module: tokio/coop R-loom Run loom tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants