Skip to content

Instantly share code, notes, and snippets.

@munro
Last active October 2, 2021 04:13
Show Gist options
  • Save munro/14219f9a671484a8fe820eb35d26bb80 to your computer and use it in GitHub Desktop.
Save munro/14219f9a671484a8fe820eb35d26bb80 to your computer and use it in GitHub Desktop.
// Rand fill buffer: 3.894 GiB/s | Instant { tv_sec: 554538, tv_nsec: 411678934 } | Rand buffer beginning: [131, 217, 107, 91, 100, 45, 141, 113, 182, 115]
// Write speed: 7.058 GiB/s | 1.416909244s | Write buffer beginning: [131, 217, 107, 91, 100, 45, 141, 113, 182, 115]
// Read speed: 10.746 GiB/s | 930.555263ms | File beginning: [131, 217, 107, 91, 100, 45, 141, 113, 182, 115]
// Verified 0 bytes look incorrect | 28.545 GiB/s | 350.32772ms
// Hardware: raid-1 two SAMSUNG MZQL23T8HCLS-00A07
// Capacity: 3.84 Tb
// Form Factor: U.2
// Seq. Read: 6.333 GiB/s
// Ran. Read: 1000k Iops
// Interface: Pcie Gen4 X4
// Seq. Write: 3.725 GiB/s
// Ran. Write: 180k Iops
use rand::{self, rngs::SmallRng, Rng, SeedableRng};
use std::time::Instant;
use tokio_uring::{self, fs::File};
fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio_uring::start(async {
let write_bytes: usize = 10 * 1024 * 1024 * 1024;
// let write_bytes: usize = 10737418240;
// let write_bytes: usize = 1024;
// generate random data
let create_buffer_start = Instant::now();
// let mut rng = SmallRng::from_seed([0; 32]);
let mut rng = SmallRng::from_entropy();
let mut write_buffer: Vec<u8> = vec![0; write_bytes];
rng.fill(&mut write_buffer[..]);
let create_buffer_duration = create_buffer_start.elapsed();
println!(
"Rand fill buffer: {:.3} GiB/s | {:?} | Rand buffer beginning: {:?}",
(write_bytes as f64) / create_buffer_duration.as_secs_f64() / 1024.0 / 1024.0 / 1024.0,
create_buffer_start,
&write_buffer[0..10]
);
// write to file
let write_file = File::create("hello.txt").await?;
let write_start = Instant::now();
let (_, write_buffer) = write_file.write_at(write_buffer, 0).await;
write_file.sync_data().await?;
// write_file.sync_all().await?;
let write_duration = write_start.elapsed();
println!(
"Write speed: {:.3} GiB/s | {:?} | Write buffer beginning: {:?}",
(write_bytes as f64) / write_duration.as_secs_f64() / 1024.0 / 1024.0 / 1024.0,
write_duration,
&write_buffer[0..10],
);
write_file.close().await?;
// read file
let read_buf: Vec<u8> = Vec::with_capacity(write_bytes);
let read_start = Instant::now();
let read_file = File::open("hello.txt").await?;
let (_, read_buf) = read_file.read_at(read_buf, 0).await;
let read_duration = read_start.elapsed();
println!(
"Read speed: {:.3} GiB/s | {:?} | File beginning: {:?}",
(write_bytes as f64) / read_duration.as_secs_f64() / 1024.0 / 1024.0 / 1024.0,
read_duration,
&read_buf[0..10],
);
read_file.close().await?;
// validate read data against written data
let verify_start = Instant::now();
let wrong_count = read_buf
.iter()
.zip(write_buffer.iter())
.filter(|(&a, &b)| a != b)
.count();
let verify_duration = verify_start.elapsed();
println!(
"Verified {} bytes look incorrect | {:.3} GiB/s | {:?}",
wrong_count,
(write_bytes as f64) / verify_duration.as_secs_f64() / 1024.0 / 1024.0 / 1024.0,
verify_duration
);
Ok(())
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment