2022-04-10 15:44:34 +00:00
|
|
|
use anyhow::Error;
|
2019-05-18 09:59:17 +00:00
|
|
|
use futures::*;
|
|
|
|
|
|
|
|
extern crate proxmox_backup;
|
|
|
|
|
2021-07-20 13:26:25 +00:00
|
|
|
use pbs_client::ChunkStream;
|
2019-05-18 09:59:17 +00:00
|
|
|
|
|
|
|
// Test Chunker with real data read from a file.
|
|
|
|
//
|
|
|
|
// To generate some test input use:
|
|
|
|
// # dd if=/dev/urandom of=random-test.dat bs=1M count=1024 iflag=fullblock
|
|
|
|
//
|
|
|
|
// Note: I can currently get about 830MB/s
|
|
|
|
|
2020-01-20 11:52:22 +00:00
|
|
|
fn main() {
|
2021-11-19 16:36:06 +00:00
|
|
|
if let Err(err) = proxmox_async::runtime::main(run()) {
|
2019-08-29 07:55:49 +00:00
|
|
|
panic!("ERROR: {}", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn run() -> Result<(), Error> {
|
|
|
|
let file = tokio::fs::File::open("random-test.dat").await?;
|
|
|
|
|
2019-12-12 14:27:07 +00:00
|
|
|
let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new())
|
2019-08-29 07:55:49 +00:00
|
|
|
.map_ok(|bytes| bytes.to_vec())
|
|
|
|
.map_err(Error::from);
|
|
|
|
|
|
|
|
//let chunk_stream = FixedChunkStream::new(stream, 4*1024*1024);
|
|
|
|
let mut chunk_stream = ChunkStream::new(stream, None);
|
|
|
|
|
|
|
|
let start_time = std::time::Instant::now();
|
|
|
|
|
|
|
|
let mut repeat = 0;
|
|
|
|
let mut stream_len = 0;
|
|
|
|
while let Some(chunk) = chunk_stream.try_next().await? {
|
2022-04-10 15:44:34 +00:00
|
|
|
if chunk.len() > 16 * 1024 * 1024 {
|
2019-08-29 07:55:49 +00:00
|
|
|
panic!("Chunk too large {}", chunk.len());
|
|
|
|
}
|
|
|
|
|
|
|
|
repeat += 1;
|
|
|
|
stream_len += chunk.len();
|
|
|
|
|
|
|
|
println!("Got chunk {}", chunk.len());
|
|
|
|
}
|
|
|
|
|
2022-04-10 15:44:34 +00:00
|
|
|
let speed =
|
|
|
|
((stream_len * 1_000_000) / (1024 * 1024)) / (start_time.elapsed().as_micros() as usize);
|
|
|
|
println!(
|
|
|
|
"Uploaded {} chunks in {} seconds ({} MB/s).",
|
|
|
|
repeat,
|
|
|
|
start_time.elapsed().as_secs(),
|
|
|
|
speed
|
|
|
|
);
|
|
|
|
println!("Average chunk size was {} bytes.", stream_len / repeat);
|
|
|
|
println!(
|
|
|
|
"time per request: {} microseconds.",
|
|
|
|
(start_time.elapsed().as_micros()) / (repeat as u128)
|
|
|
|
);
|
2019-08-29 07:55:49 +00:00
|
|
|
|
|
|
|
Ok(())
|
2019-05-18 09:59:17 +00:00
|
|
|
}
|