]>
git.proxmox.com Git - proxmox-backup.git/blob - examples/test_chunk_speed2.rs
4 extern crate proxmox_backup
;
6 use pbs_client
::ChunkStream
;
8 // Test Chunker with real data read from a file.
10 // To generate some test input use:
11 // # dd if=/dev/urandom of=random-test.dat bs=1M count=1024 iflag=fullblock
13 // Note: I can currently get about 830MB/s
16 if let Err(err
) = proxmox_async
::runtime
::main(run()) {
17 panic
!("ERROR: {}", err
);
21 async
fn run() -> Result
<(), Error
> {
22 let file
= tokio
::fs
::File
::open("random-test.dat").await?
;
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
);
28 //let chunk_stream = FixedChunkStream::new(stream, 4*1024*1024);
29 let mut chunk_stream
= ChunkStream
::new(stream
, None
);
31 let start_time
= std
::time
::Instant
::now();
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());
41 stream_len
+= chunk
.len();
43 println
!("Got chunk {}", chunk
.len());
47 ((stream_len
* 1_000_000) / (1024 * 1024)) / (start_time
.elapsed().as_micros() as usize);
49 "Uploaded {} chunks in {} seconds ({} MB/s).",
51 start_time
.elapsed().as_secs(),
54 println
!("Average chunk size was {} bytes.", stream_len
/ repeat
);
56 "time per request: {} microseconds.",
57 (start_time
.elapsed().as_micros()) / (repeat
as u128
)