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