From eb1e963fce238b5fd24f98b070a67791a07e11db Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Thu, 21 Mar 2024 00:48:34 +0530 Subject: [PATCH 1/7] Added an async runtime benchmark --- .../runtime-benchmarks/asynctest/Cargo.toml | 12 +++++ .../runtime-benchmarks/asynctest/src/main.rs | 50 +++++++++++++++++++ .../runtime-benchmarks/asynctest/src/poem.txt | 24 +++++++++ .../asynctest/src/poem2.txt | 9 ++++ 4 files changed, 95 insertions(+) create mode 100644 collector/runtime-benchmarks/asynctest/Cargo.toml create mode 100644 collector/runtime-benchmarks/asynctest/src/main.rs create mode 100644 collector/runtime-benchmarks/asynctest/src/poem.txt create mode 100644 collector/runtime-benchmarks/asynctest/src/poem2.txt diff --git a/collector/runtime-benchmarks/asynctest/Cargo.toml b/collector/runtime-benchmarks/asynctest/Cargo.toml new file mode 100644 index 000000000..f4e75f4bf --- /dev/null +++ b/collector/runtime-benchmarks/asynctest/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "asynctest" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +benchlib = { path = "../../benchlib" } +tokio = { version = "1.0", features = ["full"] } + +[workspace] \ No newline at end of file diff --git a/collector/runtime-benchmarks/asynctest/src/main.rs b/collector/runtime-benchmarks/asynctest/src/main.rs new file mode 100644 index 000000000..a6b9b168d --- /dev/null +++ b/collector/runtime-benchmarks/asynctest/src/main.rs @@ -0,0 +1,50 @@ +use benchlib::benchmark::run_benchmark_group; +use std::time::Instant; +use tokio::runtime::Runtime; +use std::fs::File; +use std::io::{self, BufRead, BufReader}; + +async fn read_the_textfile(file_path: &str) -> io::Result { + let file = File::open(file_path)?; + let reader = BufReader::new(file); + let mut total_characters = 0; + for line in reader.lines() { + let line = line?; + total_characters += line.len(); + } + + Ok(total_characters) +} + +async fn async_operation() { + let f1 = read_the_textfile("./collector/runtime-benchmarks/Async2/src/poem.txt").await.expect("Can't read file"); + let f2 = read_the_textfile("./collector/runtime-benchmarks/Async2/src/poem2.txt").await.expect("Can't read file"); + let total_char_count =f1+f2; + +} + +fn main() { + run_benchmark_group(|group| { + group.register_benchmark("Async", || { + // This closure should prepare data that will be needed for the benchmark (if any), + // and then return a closure that will actually be benchmarked/profiled. + + // Create a Tokio runtime + let rt = Runtime::new().unwrap(); + let start_time = Instant::now(); + + for _ in 0..1000 { + rt.block_on(async_operation()); + } + + let end_time = Instant::now(); + + let duration = end_time - start_time; + move || { + duration + } + }); + }); +} + + diff --git a/collector/runtime-benchmarks/asynctest/src/poem.txt b/collector/runtime-benchmarks/asynctest/src/poem.txt new file mode 100644 index 000000000..1a08d214a --- /dev/null +++ b/collector/runtime-benchmarks/asynctest/src/poem.txt @@ -0,0 +1,24 @@ +In the realm where code weaves tales bold, +A language emerged, its story untold. +With the hue of iron, sturdy and grand, +Rust stood firm on digital land. + +In the hearts of developers, it found its place, +A tool for crafting with elegance and grace. +With syntax refined, like a poet's pen, +It beckons creators, both women and men. + +In the crucible of time, it was forged with care, +To conquer challenges, it did dare. +With lifetimes borrowed from legends of old, +Rust marches forth, fearless and bold. + +It guards against errors with a vigilant eye, +Through ownership and borrowing, it helps us fly. +No more shall we fear the rust of old, +For Rust, the language, is a sight to behold. + +With concurrency, it dances in harmony's tune, +Asynchronous rhythms, like stars 'neath the moon. +In lifetimes and traits, its essence imbued, +A symphony of traits, in harmony renewed. diff --git a/collector/runtime-benchmarks/asynctest/src/poem2.txt b/collector/runtime-benchmarks/asynctest/src/poem2.txt new file mode 100644 index 000000000..6c20fa4b8 --- /dev/null +++ b/collector/runtime-benchmarks/asynctest/src/poem2.txt @@ -0,0 +1,9 @@ +O Rust, thou art a masterpiece divine, +In the kingdom of languages, you brightly shine. +With borrow checkers and lifetimes in hand, +You lead us forward, across the digital land. + +So let us raise a toast to Rust, our guide, +In its shelter, our dreams shall abide. +For in its embrace, we find our worth, +Rust, the language, the pride of Earth. \ No newline at end of file From 3cc2939460cce15ee0a05c0de2425c34871d5b25 Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Thu, 21 Mar 2024 00:54:00 +0530 Subject: [PATCH 2/7] changed the way to count characters --- collector/runtime-benchmarks/asynctest/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/runtime-benchmarks/asynctest/src/main.rs b/collector/runtime-benchmarks/asynctest/src/main.rs index a6b9b168d..1838c5405 100644 --- a/collector/runtime-benchmarks/asynctest/src/main.rs +++ b/collector/runtime-benchmarks/asynctest/src/main.rs @@ -10,7 +10,7 @@ async fn read_the_textfile(file_path: &str) -> io::Result { let mut total_characters = 0; for line in reader.lines() { let line = line?; - total_characters += line.len(); + total_characters += line.expect("invalid character").chars().count(); } Ok(total_characters) From 48024b121b61e9b3b5a39bf27394787ec878feab Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Mon, 25 Mar 2024 01:34:57 +0530 Subject: [PATCH 3/7] resolve the problems --- .../{asynctest => async}/Cargo.toml | 3 +- .../runtime-benchmarks/async/src/main.rs | 47 +++++++++++++++++ .../runtime-benchmarks/asynctest/src/main.rs | 50 ------------------- .../runtime-benchmarks/asynctest/src/poem.txt | 24 --------- .../asynctest/src/poem2.txt | 9 ---- 5 files changed, 49 insertions(+), 84 deletions(-) rename collector/runtime-benchmarks/{asynctest => async}/Cargo.toml (90%) create mode 100644 collector/runtime-benchmarks/async/src/main.rs delete mode 100644 collector/runtime-benchmarks/asynctest/src/main.rs delete mode 100644 collector/runtime-benchmarks/asynctest/src/poem.txt delete mode 100644 collector/runtime-benchmarks/asynctest/src/poem2.txt diff --git a/collector/runtime-benchmarks/asynctest/Cargo.toml b/collector/runtime-benchmarks/async/Cargo.toml similarity index 90% rename from collector/runtime-benchmarks/asynctest/Cargo.toml rename to collector/runtime-benchmarks/async/Cargo.toml index f4e75f4bf..ff49a15f4 100644 --- a/collector/runtime-benchmarks/asynctest/Cargo.toml +++ b/collector/runtime-benchmarks/async/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "asynctest" +name = "async" version = "0.1.0" edition = "2021" @@ -8,5 +8,6 @@ edition = "2021" [dependencies] benchlib = { path = "../../benchlib" } tokio = { version = "1.0", features = ["full"] } +flate2 = "1" [workspace] \ No newline at end of file diff --git a/collector/runtime-benchmarks/async/src/main.rs b/collector/runtime-benchmarks/async/src/main.rs new file mode 100644 index 000000000..22bfea038 --- /dev/null +++ b/collector/runtime-benchmarks/async/src/main.rs @@ -0,0 +1,47 @@ +use benchlib::benchmark::run_benchmark_group; +use std::time::Instant; +use tokio::runtime::Runtime; +use std::fs::File; +use std::io::{self, BufRead, BufReader}; +use flate2::read::GzDecoder; + +async fn total_char_count(reader: BufReader>,x: &mut usize) { + for line in reader.lines() { + *x += line_char_count(line.expect("invalid character")).await; + } +} + +async fn line_char_count(line: String) -> usize { + let line_count = line.chars().count(); + line_count +} + +async fn async_operation() -> (usize, u128) { + let start_time = Instant::now(); + + let file = File::open("./collector/runtime-benchmarks/data/sherlock.txt.gz").expect("can't read a file"); + let decoder = GzDecoder::new(file); + let reader2 = BufReader::new(decoder); + let mut total_char = 0; + total_char_count(reader2, &mut total_char).await; + + let end_time = Instant::now(); + let duration = end_time - start_time; + (total_char,duration.as_millis()) +} + +fn main() { + run_benchmark_group(|group| { + group.register_benchmark("Async", || { + // This closure should prepare data that will be needed for the benchmark (if any), + // and then return a closure that will actually be benchmarked/profiled. + // Create a Tokio runtime + let rt = Runtime::new().unwrap(); + move || { + rt.block_on(async_operation()); + } + }); + }); +} + + diff --git a/collector/runtime-benchmarks/asynctest/src/main.rs b/collector/runtime-benchmarks/asynctest/src/main.rs deleted file mode 100644 index 1838c5405..000000000 --- a/collector/runtime-benchmarks/asynctest/src/main.rs +++ /dev/null @@ -1,50 +0,0 @@ -use benchlib::benchmark::run_benchmark_group; -use std::time::Instant; -use tokio::runtime::Runtime; -use std::fs::File; -use std::io::{self, BufRead, BufReader}; - -async fn read_the_textfile(file_path: &str) -> io::Result { - let file = File::open(file_path)?; - let reader = BufReader::new(file); - let mut total_characters = 0; - for line in reader.lines() { - let line = line?; - total_characters += line.expect("invalid character").chars().count(); - } - - Ok(total_characters) -} - -async fn async_operation() { - let f1 = read_the_textfile("./collector/runtime-benchmarks/Async2/src/poem.txt").await.expect("Can't read file"); - let f2 = read_the_textfile("./collector/runtime-benchmarks/Async2/src/poem2.txt").await.expect("Can't read file"); - let total_char_count =f1+f2; - -} - -fn main() { - run_benchmark_group(|group| { - group.register_benchmark("Async", || { - // This closure should prepare data that will be needed for the benchmark (if any), - // and then return a closure that will actually be benchmarked/profiled. - - // Create a Tokio runtime - let rt = Runtime::new().unwrap(); - let start_time = Instant::now(); - - for _ in 0..1000 { - rt.block_on(async_operation()); - } - - let end_time = Instant::now(); - - let duration = end_time - start_time; - move || { - duration - } - }); - }); -} - - diff --git a/collector/runtime-benchmarks/asynctest/src/poem.txt b/collector/runtime-benchmarks/asynctest/src/poem.txt deleted file mode 100644 index 1a08d214a..000000000 --- a/collector/runtime-benchmarks/asynctest/src/poem.txt +++ /dev/null @@ -1,24 +0,0 @@ -In the realm where code weaves tales bold, -A language emerged, its story untold. -With the hue of iron, sturdy and grand, -Rust stood firm on digital land. - -In the hearts of developers, it found its place, -A tool for crafting with elegance and grace. -With syntax refined, like a poet's pen, -It beckons creators, both women and men. - -In the crucible of time, it was forged with care, -To conquer challenges, it did dare. -With lifetimes borrowed from legends of old, -Rust marches forth, fearless and bold. - -It guards against errors with a vigilant eye, -Through ownership and borrowing, it helps us fly. -No more shall we fear the rust of old, -For Rust, the language, is a sight to behold. - -With concurrency, it dances in harmony's tune, -Asynchronous rhythms, like stars 'neath the moon. -In lifetimes and traits, its essence imbued, -A symphony of traits, in harmony renewed. diff --git a/collector/runtime-benchmarks/asynctest/src/poem2.txt b/collector/runtime-benchmarks/asynctest/src/poem2.txt deleted file mode 100644 index 6c20fa4b8..000000000 --- a/collector/runtime-benchmarks/asynctest/src/poem2.txt +++ /dev/null @@ -1,9 +0,0 @@ -O Rust, thou art a masterpiece divine, -In the kingdom of languages, you brightly shine. -With borrow checkers and lifetimes in hand, -You lead us forward, across the digital land. - -So let us raise a toast to Rust, our guide, -In its shelter, our dreams shall abide. -For in its embrace, we find our worth, -Rust, the language, the pride of Earth. \ No newline at end of file From 51b79823914343b168458cb0c482327204d98ed1 Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Tue, 26 Mar 2024 00:07:26 +0530 Subject: [PATCH 4/7] "resolved the comments" --- collector/runtime-benchmarks/async/Cargo.toml | 2 +- .../runtime-benchmarks/async/src/main.rs | 24 ++++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/collector/runtime-benchmarks/async/Cargo.toml b/collector/runtime-benchmarks/async/Cargo.toml index ff49a15f4..a31d4e175 100644 --- a/collector/runtime-benchmarks/async/Cargo.toml +++ b/collector/runtime-benchmarks/async/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "async" +name = "async-bench" version = "0.1.0" edition = "2021" diff --git a/collector/runtime-benchmarks/async/src/main.rs b/collector/runtime-benchmarks/async/src/main.rs index 22bfea038..84624d2ea 100644 --- a/collector/runtime-benchmarks/async/src/main.rs +++ b/collector/runtime-benchmarks/async/src/main.rs @@ -1,8 +1,7 @@ use benchlib::benchmark::run_benchmark_group; -use std::time::Instant; -use tokio::runtime::Runtime; +use tokio::runtime::Builder; use std::fs::File; -use std::io::{self, BufRead, BufReader}; +use std::io::{BufRead, BufReader}; use flate2::read::GzDecoder; async fn total_char_count(reader: BufReader>,x: &mut usize) { @@ -16,18 +15,11 @@ async fn line_char_count(line: String) -> usize { line_count } -async fn async_operation() -> (usize, u128) { - let start_time = Instant::now(); - - let file = File::open("./collector/runtime-benchmarks/data/sherlock.txt.gz").expect("can't read a file"); - let decoder = GzDecoder::new(file); - let reader2 = BufReader::new(decoder); +async fn async_operation() -> usize { + let reader2 = BufReader::new(GzDecoder::new(File::open("./collector/runtime-benchmarks/data/sherlock.txt.gz").expect("can't read a file"))); let mut total_char = 0; total_char_count(reader2, &mut total_char).await; - - let end_time = Instant::now(); - let duration = end_time - start_time; - (total_char,duration.as_millis()) + total_char } fn main() { @@ -36,7 +28,11 @@ fn main() { // This closure should prepare data that will be needed for the benchmark (if any), // and then return a closure that will actually be benchmarked/profiled. // Create a Tokio runtime - let rt = Runtime::new().unwrap(); + let rt = Builder::new_multi_thread() + .worker_threads(1) + .enable_all() + .build() + .unwrap(); move || { rt.block_on(async_operation()); } From 69d94deaced78ec2ec297f3c9ec82035f5ddd7c9 Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Wed, 27 Mar 2024 18:22:58 +0530 Subject: [PATCH 5/7] Added Cargo.lock and improved the code --- collector/runtime-benchmarks/async/Cargo.lock | 750 ++++++++++++++++++ collector/runtime-benchmarks/async/Cargo.toml | 3 +- .../runtime-benchmarks/async/src/main.rs | 32 +- 3 files changed, 767 insertions(+), 18 deletions(-) create mode 100644 collector/runtime-benchmarks/async/Cargo.lock diff --git a/collector/runtime-benchmarks/async/Cargo.lock b/collector/runtime-benchmarks/async/Cargo.lock new file mode 100644 index 000000000..990422b26 --- /dev/null +++ b/collector/runtime-benchmarks/async/Cargo.lock @@ -0,0 +1,750 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + +[[package]] +name = "async-bench" +version = "0.1.0" +dependencies = [ + "benchlib", + "tokio", +] + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "benchlib" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "env_logger", + "flate2", + "libc", + "log", + "perf-event", + "serde", + "serde_json", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + +[[package]] +name = "perf-event" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4d6393d9238342159080d79b78cb59c67399a8e7ecfa5d410bd614169e4e823" +dependencies = [ + "libc", + "perf-event-open-sys", +] + +[[package]] +name = "perf-event-open-sys" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c44fb1c7651a45a3652c4afc6e754e40b3d6e6556f1487e2b230bfc4f33c2a8" +dependencies = [ + "libc", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + +[[package]] +name = "syn" +version = "2.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "tokio" +version = "1.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" diff --git a/collector/runtime-benchmarks/async/Cargo.toml b/collector/runtime-benchmarks/async/Cargo.toml index a31d4e175..1697daa3d 100644 --- a/collector/runtime-benchmarks/async/Cargo.toml +++ b/collector/runtime-benchmarks/async/Cargo.toml @@ -6,8 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -benchlib = { path = "../../benchlib" } +benchlib = { path = "../../benchlib", features = ["compression"]} tokio = { version = "1.0", features = ["full"] } -flate2 = "1" [workspace] \ No newline at end of file diff --git a/collector/runtime-benchmarks/async/src/main.rs b/collector/runtime-benchmarks/async/src/main.rs index 84624d2ea..bb10798c8 100644 --- a/collector/runtime-benchmarks/async/src/main.rs +++ b/collector/runtime-benchmarks/async/src/main.rs @@ -1,40 +1,40 @@ use benchlib::benchmark::run_benchmark_group; use tokio::runtime::Builder; -use std::fs::File; -use std::io::{BufRead, BufReader}; -use flate2::read::GzDecoder; +use benchlib::decompress_file; -async fn total_char_count(reader: BufReader>,x: &mut usize) { +const TEXT_SHERLOCK: &[u8] = include_bytes!("../../data/sherlock.txt.gz"); + +async fn total_char_count(reader: String) -> usize{ + let mut total_char = 0; for line in reader.lines() { - *x += line_char_count(line.expect("invalid character")).await; + total_char += line_char_count(line).await; } + total_char } -async fn line_char_count(line: String) -> usize { - let line_count = line.chars().count(); - line_count +async fn line_char_count(line: &str) -> usize { + let char_count = line.chars().count(); + char_count } async fn async_operation() -> usize { - let reader2 = BufReader::new(GzDecoder::new(File::open("./collector/runtime-benchmarks/data/sherlock.txt.gz").expect("can't read a file"))); - let mut total_char = 0; - total_char_count(reader2, &mut total_char).await; + let sherlock_text = String::from_utf8(decompress_file(TEXT_SHERLOCK)).expect("Invalid UTF-8"); + let total_char = total_char_count(sherlock_text).await; total_char } fn main() { run_benchmark_group(|group| { - group.register_benchmark("Async", || { + group.register_benchmark("async-word-count", || { // This closure should prepare data that will be needed for the benchmark (if any), // and then return a closure that will actually be benchmarked/profiled. // Create a Tokio runtime - let rt = Builder::new_multi_thread() - .worker_threads(1) + let rt = Builder::new_current_thread() .enable_all() .build() - .unwrap(); + .unwrap(); move || { - rt.block_on(async_operation()); + rt.block_on(async_operation()) } }); }); From 77900e3c04e34377a6b090f123c6d7d31e913fbd Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Fri, 12 Apr 2024 23:14:10 +0530 Subject: [PATCH 6/7] increased size of string --- collector/runtime-benchmarks/async/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/runtime-benchmarks/async/src/main.rs b/collector/runtime-benchmarks/async/src/main.rs index bb10798c8..e4db770ac 100644 --- a/collector/runtime-benchmarks/async/src/main.rs +++ b/collector/runtime-benchmarks/async/src/main.rs @@ -18,7 +18,7 @@ async fn line_char_count(line: &str) -> usize { } async fn async_operation() -> usize { - let sherlock_text = String::from_utf8(decompress_file(TEXT_SHERLOCK)).expect("Invalid UTF-8"); + let sherlock_text = (String::from_utf8(decompress_file(TEXT_SHERLOCK)).expect("Invalid UTF-8")).repeat(20); let total_char = total_char_count(sherlock_text).await; total_char } From 8868473717d2304c8cf1b4b42fc23438dd8dbffc Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Sun, 21 Apr 2024 17:24:28 +0530 Subject: [PATCH 7/7] I/O operations in memory giving chance to execute asynchronously --- collector/runtime-benchmarks/async/src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/collector/runtime-benchmarks/async/src/main.rs b/collector/runtime-benchmarks/async/src/main.rs index e4db770ac..d94ed5469 100644 --- a/collector/runtime-benchmarks/async/src/main.rs +++ b/collector/runtime-benchmarks/async/src/main.rs @@ -6,19 +6,24 @@ const TEXT_SHERLOCK: &[u8] = include_bytes!("../../data/sherlock.txt.gz"); async fn total_char_count(reader: String) -> usize{ let mut total_char = 0; + for line in reader.lines() { - total_char += line_char_count(line).await; + let mut vec: Vec<&str> = Vec::new(); + total_char += line.chars().count(); + let big :String= line.to_string().repeat(100); + push_and_pop(&mut vec, &big).await; } total_char } -async fn line_char_count(line: &str) -> usize { - let char_count = line.chars().count(); - char_count + +async fn push_and_pop<'a>(vec: &'a mut Vec<&'a str>, line: &'a String){ + vec.push(line.as_str()); + vec.pop().unwrap(); } async fn async_operation() -> usize { - let sherlock_text = (String::from_utf8(decompress_file(TEXT_SHERLOCK)).expect("Invalid UTF-8")).repeat(20); + let sherlock_text = String::from_utf8(decompress_file(TEXT_SHERLOCK)).expect("Invalid UTF-8"); let total_char = total_char_count(sherlock_text).await; total_char }