-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix third-party vulnerability caused by atty v0.2.14 (#644)
* Update Clap version to 4.6 Github detects third-party vulnerabilities seems to originate from the old version of clap. * fix fmt * Replace pretty-bytes with byte-unit
- Loading branch information
Showing
2 changed files
with
39 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use clap::{App, Arg}; | ||
use byte_unit::{Byte, UnitType}; | ||
use clap::{Arg, Command}; | ||
use futures_lite::{ | ||
stream::{self, StreamExt}, | ||
AsyncReadExt, AsyncWriteExt, | ||
|
@@ -11,7 +12,6 @@ use glommio::{ | |
}, | ||
LocalExecutorBuilder, Placement, | ||
}; | ||
use pretty_bytes::converter; | ||
use std::{ | ||
cell::Cell, | ||
fs, | ||
|
@@ -51,13 +51,17 @@ async fn stream_write<T: AsyncWriteExt + std::marker::Unpin, S: Into<String>>( | |
|
||
let endw = Instant::now(); | ||
let time = start.elapsed(); | ||
let bytes = converter::convert(file_size as _); | ||
let rate = converter::convert((file_size as f64 / time.as_secs_f64()) as _); | ||
println!("{name}: Wrote {bytes} in {time:#?}, {rate}/s"); | ||
let bytes = Byte::from_u64(file_size).get_appropriate_unit(UnitType::Binary); | ||
let rate = Byte::from_f64(file_size as f64 / time.as_secs_f64()) | ||
.unwrap_or_default() | ||
.get_appropriate_unit(UnitType::Binary); | ||
println!("{name}: Wrote {bytes:.2} in {time:#?}, {rate:.2}/s"); | ||
stream.close().await.unwrap(); | ||
let rate = converter::convert((file_size as f64 / start.elapsed().as_secs_f64()) as _); | ||
let rate = Byte::from_f64(file_size as f64 / start.elapsed().as_secs_f64()) | ||
.unwrap_or_default() | ||
.get_appropriate_unit(UnitType::Binary); | ||
let time = endw.elapsed(); | ||
println!("{name}: Closed in {time:#?}, Amortized total {rate}/s"); | ||
println!("{name}: Closed in {time:#?}, Amortized total {rate:.2}/s"); | ||
} | ||
|
||
async fn stream_scan<T: AsyncReadExt + std::marker::Unpin, S: Into<String>>( | ||
|
@@ -82,10 +86,12 @@ async fn stream_scan<T: AsyncReadExt + std::marker::Unpin, S: Into<String>>( | |
let time = start.elapsed(); | ||
let name = name.into(); | ||
|
||
let bytes = converter::convert(bytes_read as _); | ||
let rate = converter::convert((bytes_read as f64 / time.as_secs_f64()) as _); | ||
let bytes = Byte::from_u64(bytes_read as _).get_appropriate_unit(UnitType::Binary); | ||
let rate = Byte::from_f64(bytes_read as f64 / time.as_secs_f64()) | ||
.unwrap_or_default() | ||
.get_appropriate_unit(UnitType::Binary); | ||
println!( | ||
"{name}: Scanned {bytes} in {time:#?}, {rate}/s, {} IOPS", | ||
"{name}: Scanned {bytes:.2} in {time:#?}, {rate:.2}/s, {} IOPS", | ||
(ops as f64 / time.as_secs_f64()) as usize | ||
); | ||
stream | ||
|
@@ -115,10 +121,12 @@ async fn stream_scan_alt_api<S: Into<String>>( | |
let time = start.elapsed(); | ||
let name = name.into(); | ||
|
||
let bytes = converter::convert(bytes_read as _); | ||
let rate = converter::convert((bytes_read as f64 / time.as_secs_f64()) as _); | ||
let bytes = Byte::from_u64(bytes_read as _).get_appropriate_unit(UnitType::Binary); | ||
let rate = Byte::from_f64(bytes_read as f64 / time.as_secs_f64()) | ||
.unwrap_or_default() | ||
.get_appropriate_unit(UnitType::Binary); | ||
println!( | ||
"{name}: Scanned {bytes} in {time:#?}, {rate}/s, {} IOPS", | ||
"{name}: Scanned {bytes:.2} in {time:#?}, {rate:.2}/s, {} IOPS", | ||
(ops as f64 / time.as_secs_f64()) as usize | ||
); | ||
stream.close().await.unwrap(); | ||
|
@@ -212,11 +220,11 @@ async fn random_read<S: Into<String>>( | |
Ok(file) => file.close().await, | ||
}; | ||
|
||
assert_eq!(finished, parallelism as _); | ||
let bytes = converter::convert(random as _); | ||
assert_eq!(finished, parallelism); | ||
let bytes = Byte::from_u64(random).get_appropriate_unit(UnitType::Binary); | ||
let dur = time.elapsed(); | ||
println!( | ||
"{name}: Random Read (uniform) size span of {bytes}, for {dur:#?}, {} IOPS", | ||
"{name}: Random Read (uniform) size span of {bytes:.2}, for {dur:#?}, {} IOPS", | ||
(iops.get() as f64 / dur.as_secs_f64()) as usize | ||
); | ||
} | ||
|
@@ -261,39 +269,39 @@ async fn random_many_read<S: Into<String>>( | |
Ok(file) => file.close().await, | ||
}; | ||
|
||
assert_eq!(finished, parallelism as _); | ||
let bytes = converter::convert(random as _); | ||
let max_merged = converter::convert(max_buffer_size as _); | ||
assert_eq!(finished, parallelism); | ||
let bytes = Byte::from_u64(random).get_appropriate_unit(UnitType::Binary); | ||
let max_merged = Byte::from_u64(max_buffer_size as _).get_appropriate_unit(UnitType::Binary); | ||
let dur = time.elapsed(); | ||
println!( | ||
"{name}: Random Bulk Read (uniform) size span of {bytes}, for {dur:#?} (max merged size \ | ||
of {max_merged}), {} IOPS", | ||
"{name}: Random Bulk Read (uniform) size span of {bytes:.2}, for {dur:#?} (max merged size \ | ||
of {max_merged:.2}), {} IOPS", | ||
(iops.get() as f64 / dur.as_secs_f64()) as usize | ||
); | ||
} | ||
|
||
fn main() { | ||
let matches = App::new("storage example") | ||
let matches = Command::new("storage example") | ||
.version("0.1.0") | ||
.author("Glauber Costa <[email protected]>") | ||
.about("demonstrate glommio's storage APIs") | ||
.arg( | ||
Arg::with_name("storage_dir") | ||
Arg::new("storage_dir") | ||
.long("dir") | ||
.takes_value(true) | ||
.action(clap::ArgAction::Set) | ||
.required(true) | ||
.help("The directory where to write and read file for this test"), | ||
) | ||
.arg( | ||
Arg::with_name("file_size") | ||
Arg::new("file_size") | ||
.long("size-gb") | ||
.takes_value(true) | ||
.action(clap::ArgAction::Set) | ||
.required(false) | ||
.help("size of the file in GB (default: 2 * memory_size)"), | ||
) | ||
.get_matches(); | ||
|
||
let path = matches.value_of("storage_dir").unwrap(); | ||
let path = matches.get_one::<String>("storage_dir").unwrap(); | ||
let mut dir = PathBuf::from(path); | ||
assert!(dir.exists()); | ||
dir.push("benchfiles"); | ||
|
@@ -303,8 +311,8 @@ fn main() { | |
let total_memory = sys_info::mem_info().unwrap().total << 10; | ||
|
||
let file_size = matches | ||
.value_of("file_size") | ||
.map(|s| s.parse::<u64>().unwrap() << 30) | ||
.get_one::<u64>("file_size") | ||
.map(|s| s << 30) | ||
.unwrap_or(total_memory * 2); | ||
|
||
let random = total_memory / 10; | ||
|