]> git.proxmox.com Git - proxmox-backup.git/blame - src/bin/test_chunk_speed2.rs
introduce new runtime tokio helpers
[proxmox-backup.git] / src / bin / test_chunk_speed2.rs
CommitLineData
62764485
DM
1use failure::*;
2use futures::*;
62764485
DM
3
4extern crate proxmox_backup;
5
6use proxmox_backup::backup::*;
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
d973aa82
WB
15fn main() {
16 if let Err(err) = proxmox_backup::tools::runtime::main(run()) {
cab68169
WB
17 panic!("ERROR: {}", err);
18 }
19}
20
21async fn run() -> Result<(), Error> {
22
23 let file = tokio::fs::File::open("random-test.dat").await?;
24
db0cb9ce 25 let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new())
cab68169
WB
26 .map_ok(|bytes| bytes.to_vec())
27 .map_err(Error::from);
28
29 //let chunk_stream = FixedChunkStream::new(stream, 4*1024*1024);
30 let mut chunk_stream = ChunkStream::new(stream, None);
31
32 let start_time = std::time::Instant::now();
33
34 let mut repeat = 0;
35 let mut stream_len = 0;
36 while let Some(chunk) = chunk_stream.try_next().await? {
37 if chunk.len() > 16*1024*1024 {
38 panic!("Chunk too large {}", chunk.len());
39 }
40
41 repeat += 1;
42 stream_len += chunk.len();
43
44 println!("Got chunk {}", chunk.len());
45 }
46
11377a47 47 let speed = ((stream_len*1_000_000)/(1024*1024))/(start_time.elapsed().as_micros() as usize);
cab68169
WB
48 println!("Uploaded {} chunks in {} seconds ({} MB/s).", repeat, start_time.elapsed().as_secs(), speed);
49 println!("Average chunk size was {} bytes.", stream_len/repeat);
50 println!("time per request: {} microseconds.", (start_time.elapsed().as_micros())/(repeat as u128));
51
52 Ok(())
62764485 53}