proxmox-backup-client benchmark: add --verbose flag

This commit is contained in:
Dietmar Maurer 2020-07-09 16:16:39 +02:00
parent 7884e7ef4f
commit 323b2f3dd6
2 changed files with 17 additions and 8 deletions

View File

@ -30,6 +30,11 @@ use crate::{
schema: REPO_URL_SCHEMA, schema: REPO_URL_SCHEMA,
optional: true, optional: true,
}, },
verbose: {
description: "Verbose output.",
type: bool,
optional: true,
},
keyfile: { keyfile: {
schema: KEYFILE_SCHEMA, schema: KEYFILE_SCHEMA,
optional: true, optional: true,
@ -48,6 +53,8 @@ pub async fn benchmark(
let keyfile = param["keyfile"].as_str().map(PathBuf::from); let keyfile = param["keyfile"].as_str().map(PathBuf::from);
let verbose = param["verbose"].as_bool().unwrap_or(false);
let crypt_config = match keyfile { let crypt_config = match keyfile {
None => None, None => None,
Some(path) => { Some(path) => {
@ -62,18 +69,19 @@ pub async fn benchmark(
let client = connect(repo.host(), repo.user())?; let client = connect(repo.host(), repo.user())?;
record_repository(&repo); record_repository(&repo);
println!("Connecting to backup server");
let client = BackupWriter::start( let client = BackupWriter::start(
client, client,
crypt_config.clone(), crypt_config.clone(),
repo.store(), repo.store(),
"host", "host",
"benshmark", "benchmark",
backup_time, backup_time,
false, false,
).await?; ).await?;
println!("Start upload speed test"); println!("Start upload speed test");
let speed = client.upload_speedtest().await?; let speed = client.upload_speedtest(verbose).await?;
println!("Upload speed: {} MiB/s", speed); println!("Upload speed: {} MiB/s", speed);

View File

@ -274,7 +274,7 @@ impl BackupWriter {
}) })
} }
fn response_queue() -> ( fn response_queue(verbose: bool) -> (
mpsc::Sender<h2::client::ResponseFuture>, mpsc::Sender<h2::client::ResponseFuture>,
oneshot::Receiver<Result<(), Error>> oneshot::Receiver<Result<(), Error>>
) { ) {
@ -298,11 +298,11 @@ impl BackupWriter {
tokio::spawn( tokio::spawn(
verify_queue_rx verify_queue_rx
.map(Ok::<_, Error>) .map(Ok::<_, Error>)
.try_for_each(|response: h2::client::ResponseFuture| { .try_for_each(move |response: h2::client::ResponseFuture| {
response response
.map_err(Error::from) .map_err(Error::from)
.and_then(H2Client::h2api_response) .and_then(H2Client::h2api_response)
.map_ok(|result| println!("RESPONSE: {:?}", result)) .map_ok(move |result| if verbose { println!("RESPONSE: {:?}", result) })
.map_err(|err| format_err!("pipelined request failed: {}", err)) .map_err(|err| format_err!("pipelined request failed: {}", err))
}) })
.map(|result| { .map(|result| {
@ -600,7 +600,8 @@ impl BackupWriter {
}) })
} }
pub async fn upload_speedtest(&self) -> Result<usize, Error> { /// Upload speed test - prints result ot stdout
pub async fn upload_speedtest(&self, verbose: bool) -> Result<usize, Error> {
let mut data = vec![]; let mut data = vec![];
// generate pseudo random byte sequence // generate pseudo random byte sequence
@ -615,7 +616,7 @@ impl BackupWriter {
let mut repeat = 0; let mut repeat = 0;
let (upload_queue, upload_result) = Self::response_queue(); let (upload_queue, upload_result) = Self::response_queue(verbose);
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
@ -627,7 +628,7 @@ impl BackupWriter {
let mut upload_queue = upload_queue.clone(); let mut upload_queue = upload_queue.clone();
println!("send test data ({} bytes)", data.len()); if verbose { println!("send test data ({} bytes)", data.len()); }
let request = H2Client::request_builder("localhost", "POST", "speedtest", None, None).unwrap(); let request = H2Client::request_builder("localhost", "POST", "speedtest", None, None).unwrap();
let request_future = self.h2.send_request(request, Some(bytes::Bytes::from(data.clone()))).await?; let request_future = self.h2.send_request(request, Some(bytes::Bytes::from(data.clone()))).await?;