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

Validate execCPUAffinity of the runtime process spec #178

Merged
merged 8 commits into from
Jul 5, 2024

Conversation

keisku
Copy link
Contributor

@keisku keisku commented Jul 2, 2024

@keisku keisku marked this pull request as draft July 2, 2024 13:35
@keisku keisku force-pushed the execCPUAffinity-validation branch 2 times, most recently from a67075d to 52804f0 Compare July 2, 2024 13:41
@keisku keisku marked this pull request as ready for review July 2, 2024 13:43
@saschagrunert
Copy link
Contributor

@keisku thank you for the PR, do you mind a rebase?

Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
@keisku keisku force-pushed the execCPUAffinity-validation branch from 11635cd to 18a85b2 Compare July 3, 2024 13:28
@keisku
Copy link
Contributor Author

keisku commented Jul 3, 2024

@saschagrunert I did!

src/runtime/process.rs Outdated Show resolved Hide resolved
src/runtime/process.rs Outdated Show resolved Hide resolved
Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
@saschagrunert
Copy link
Contributor

@utam0k PTAL

@@ -32,6 +32,8 @@ derive_builder = "0.20.0"
getset = "0.1.1"
strum = "0.26.2"
strum_macros = "0.26.2"
regex = "1.10.5"
Copy link
Member

Choose a reason for hiding this comment

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

I'm worried about performance by introducing regex. WDYT? @saschagrunert

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I agree, not sure I like that dependency right here.

Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
@keisku
Copy link
Contributor Author

keisku commented Jul 4, 2024

@saschagrunert @utam0k Reimplemented the validation logic without regex and once_cell!

@utam0k
Copy link
Member

utam0k commented Jul 4, 2024

@keisku Thanks, but apparently, the regex implementation is faster than the current implementation you updated. Depending on the length of the string, both are fast enough to merge. Sorry, can you revert to the regex implementation?

$ cargo bench
simple_perf             time:   [99.829 ns 100.50 ns 101.24 ns]
                        change: [-0.6423% +0.6216% +1.7508%] (p = 0.33 > 0.05)
                        No change in performance detected.
Found 8 outliers among 100 measurements (8.00%)
  7 (7.00%) high mild
  1 (1.00%) high severe

regex_perf              time:   [24.250 ns 24.451 ns 24.669 ns]
                        change: [-2.0247% -0.9518% +0.1010%] (p = 0.08 > 0.05)
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  4 (4.00%) high mild
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use regex::Regex;

fn regex_benchmark(c: &mut Criterion) {
    c.bench_function("regex_perf", |b| {
        let re = Regex::new(r"^(\d+(-\d+)?)(,\d+(-\d+)?)*$").unwrap();
        b.iter(|| re.is_match(black_box("123,456-789,22,1,2,4,5,6")));
    });
}

fn simple_benchmark(c: &mut Criterion) {
    c.bench_function("simple_perf", |b| {
        b.iter(|| {
            let s = black_box("123,456-789,22,1,2,4,5,6");
            let iter = s.split(',');

            for part in iter {
                let mut range_iter = part.split('-');
                range_iter
                    .next()
                    .ok_or_else(|| format!("Invalid execCPUAffinity format: {}", s))
                    .unwrap();

                // Check if there's a range and if the end is a valid number
                if let Some(end) = range_iter.next() {
                    end.parse::<usize>().unwrap();
                }

                // Ensure there's no extra data after the end of a range
                if range_iter.next().is_some() {
                    panic!("Invalid execCPUAffinity format: {}", s);
                }
            }
        });
    });
}

criterion_group!(benches, simple_benchmark, regex_benchmark);
criterion_main!(benches);

This reverts commit 73c9740.

Signed-off-by: keisku <keisuke.umegaki.630@gmail.com>
@keisku keisku requested a review from utam0k July 4, 2024 13:23
@utam0k utam0k merged commit c49f5b6 into youki-dev:main Jul 5, 2024
13 checks passed
@keisku keisku mentioned this pull request Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants