proxmox-backup-client benchamrk: add more speed tests

This commit is contained in:
Dietmar Maurer 2020-07-09 17:07:22 +02:00
parent e193544b8e
commit 4327a8462a

View File

@ -9,9 +9,9 @@ use proxmox::api::{ApiMethod, RpcEnvironment};
use proxmox::api::api;
use proxmox_backup::backup::{
load_and_decrypt_key,
CryptConfig,
load_and_decrypt_key,
CryptConfig,
KeyDerivationConfig,
};
use proxmox_backup::client::*;
@ -64,12 +64,14 @@ pub async fn benchmark(
}
};
test_crypt_speed(verbose)?;
let backup_time = Utc.timestamp(Utc::now().timestamp(), 0);
let client = connect(repo.host(), repo.user())?;
record_repository(&repo);
println!("Connecting to backup server");
if verbose { println!("Connecting to backup server"); }
let client = BackupWriter::start(
client,
crypt_config.clone(),
@ -80,10 +82,91 @@ pub async fn benchmark(
false,
).await?;
println!("Start upload speed test");
if verbose { println!("Start upload speed test"); }
let speed = client.upload_speedtest(verbose).await?;
println!("Upload speed: {} MiB/s", speed);
Ok(())
}
// test SHA256 speed
fn test_crypt_speed(verbose: bool) -> Result<(), Error> {
let pw = b"test";
let kdf = KeyDerivationConfig::Scrypt {
n: 65536,
r: 8,
p: 1,
salt: Vec::new(),
};
let testkey = kdf.derive_key(pw)?;
let crypt_config = CryptConfig::new(testkey)?;
let random_data = proxmox::sys::linux::random_data(1024*1024)?;
let start_time = std::time::Instant::now();
let mut bytes = 0;
loop {
openssl::sha::sha256(&random_data);
bytes += random_data.len();
if start_time.elapsed().as_micros() > 1_000_000 { break; }
}
let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
println!("SHA256 speed: {:.2} MB/s", speed/1_000_000_.0);
let start_time = std::time::Instant::now();
let mut bytes = 0;
loop {
let mut reader = &random_data[..];
zstd::stream::encode_all(&mut reader, 1)?;
bytes += random_data.len();
if start_time.elapsed().as_micros() > 1_000_000 { break; }
}
let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
println!("Compression speed: {:.2} MB/s", speed/1_000_000_.0);
let start_time = std::time::Instant::now();
let compressed_data = {
let mut reader = &random_data[..];
zstd::stream::encode_all(&mut reader, 1)?
};
let mut bytes = 0;
loop {
let mut reader = &compressed_data[..];
let data = zstd::stream::decode_all(&mut reader)?;
bytes += data.len();
if start_time.elapsed().as_micros() > 1_000_000 { break; }
}
let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
println!("Decompress speed: {:.2} MB/s", speed/1_000_000_.0);
let start_time = std::time::Instant::now();
let mut bytes = 0;
loop {
let mut out = Vec::new();
crypt_config.encrypt_to(&random_data, &mut out);
bytes += random_data.len();
if start_time.elapsed().as_micros() > 1_000_000 { break; }
}
let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
println!("AES256/GCM speed: {:.2} MB/s", speed/1_000_000_.0);
Ok(())
}