]> git.proxmox.com Git - proxmox-backup.git/blob - examples/test_chunk_speed2.rs
split the namespace out of BackupGroup/Dir api types
[proxmox-backup.git] / examples / test_chunk_speed2.rs
1 use anyhow::Error;
2 use futures::*;
3
4 extern crate proxmox_backup;
5
6 use pbs_client::ChunkStream;
7
8 // Test Chunker with real data read from a file.
9 //
10 // To generate some test input use:
11 // # dd if=/dev/urandom of=random-test.dat bs=1M count=1024 iflag=fullblock
12 //
13 // Note: I can currently get about 830MB/s
14
15 fn main() {
16 if let Err(err) = proxmox_async::runtime::main(run()) {
17 panic!("ERROR: {}", err);
18 }
19 }
20
21 async fn run() -> Result<(), Error> {
22 let file = tokio::fs::File::open("random-test.dat").await?;
23
24 let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new())
25 .map_ok(|bytes| bytes.to_vec())
26 .map_err(Error::from);
27
28 //let chunk_stream = FixedChunkStream::new(stream, 4*1024*1024);
29 let mut chunk_stream = ChunkStream::new(stream, None);
30
31 let start_time = std::time::Instant::now();
32
33 let mut repeat = 0;
34 let mut stream_len = 0;
35 while let Some(chunk) = chunk_stream.try_next().await? {
36 if chunk.len() > 16 * 1024 * 1024 {
37 panic!("Chunk too large {}", chunk.len());
38 }
39
40 repeat += 1;
41 stream_len += chunk.len();
42
43 println!("Got chunk {}", chunk.len());
44 }
45
46 let speed =
47 ((stream_len * 1_000_000) / (1024 * 1024)) / (start_time.elapsed().as_micros() as usize);
48 println!(
49 "Uploaded {} chunks in {} seconds ({} MB/s).",
50 repeat,
51 start_time.elapsed().as_secs(),
52 speed
53 );
54 println!("Average chunk size was {} bytes.", stream_len / repeat);
55 println!(
56 "time per request: {} microseconds.",
57 (start_time.elapsed().as_micros()) / (repeat as u128)
58 );
59
60 Ok(())
61 }