From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 2/2] api: parallelize smartctl checks
Date: Tue, 17 Sep 2024 10:05:50 +0200 [thread overview]
Message-ID: <20240917080550.51803-2-g.goller@proxmox.com> (raw)
In-Reply-To: <20240917080550.51803-1-g.goller@proxmox.com>
To improve the performance of the smartctl checks, especially when a lot
of disks are used, parallelize the checks using the `ParallelHandler`.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
Benchmark:
Benchmark 1: proxmox-backup-manager disk list (parallel)
Time (mean ± σ): 75.8 ms ± 5.7 ms [User: 0.8 ms, System: 0.5 ms]
Range (min … max): 63.4 ms … 95.3 ms 100 runs
Benchmark 2: proxmox-backup-manager disk list (sequential)
Time (mean ± σ): 189.4 ms ± 6.7 ms [User: 0.7 ms, System: 1.0 ms]
Range (min … max): 178.8 ms … 223.0 ms 100 runs
Summary
'proxmox-backup-manager disk list (parallel)' ran
2.50 ± 0.21 times faster than 'proxmox-backup-manager disk list (sequential)'
src/tools/disks/mod.rs | 42 +++++++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 13 deletions(-)
v2, thanks @shannon:
- fixed charset of email
diff --git a/src/tools/disks/mod.rs b/src/tools/disks/mod.rs
index 04f62b818238..09a3003a9333 100644
--- a/src/tools/disks/mod.rs
+++ b/src/tools/disks/mod.rs
@@ -15,13 +15,15 @@ use once_cell::sync::OnceCell;
use ::serde::{Deserialize, Serialize};
use proxmox_lang::{io_bail, io_format_err};
+use proxmox_log::info;
use proxmox_schema::api;
use proxmox_sys::linux::procfs::{mountinfo::Device, MountInfo};
use pbs_api_types::{BLOCKDEVICE_DISK_AND_PARTITION_NAME_REGEX, BLOCKDEVICE_NAME_REGEX};
+use crate::tools::parallel_handler::ParallelHandler;
+
mod zfs;
-use tracing::info;
pub use zfs::*;
mod zpool_status;
pub use zpool_status::*;
@@ -1047,16 +1049,6 @@ fn get_disks(
usage = DiskUsageType::DeviceMapper;
}
- let mut status = SmartStatus::Unknown;
- let mut wearout = None;
-
- if !no_smart {
- if let Ok(smart) = get_smart_data(&disk, false) {
- status = smart.status;
- wearout = smart.wearout;
- }
- }
-
let info = DiskUsageInfo {
name: name.clone(),
vendor,
@@ -1067,8 +1059,8 @@ fn get_disks(
size,
wwn,
disk_type,
- status,
- wearout,
+ status: SmartStatus::Unknown,
+ wearout: None,
used: usage,
gpt: disk.has_gpt(),
rpm: disk.ata_rotation_rate_rpm(),
@@ -1077,6 +1069,30 @@ fn get_disks(
result.insert(name, info);
}
+ if !no_smart {
+ let (tx, rx) = crossbeam_channel::bounded(result.len());
+
+ let parallel_handler =
+ ParallelHandler::new("smartctl data", 4, move |device: (String, String)| {
+ let smart_data = get_smart_data(Path::new(&device.1), false)?;
+ tx.send((device.0, smart_data))?;
+ Ok(())
+ });
+
+ for (name, path) in device_paths.into_iter() {
+ if let Some(p) = path {
+ parallel_handler.send((name, p))?;
+ }
+ }
+
+ parallel_handler.complete()?;
+ while let Ok(msg) = rx.recv() {
+ if let Some(value) = result.get_mut(&msg.0) {
+ value.wearout = msg.1.wearout;
+ value.status = msg.1.status;
+ }
+ }
+ }
Ok(result)
}
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
prev parent reply other threads:[~2024-09-17 8:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-17 8:05 [pbs-devel] [PATCH proxmox-backup v2 1/2] api: avoid retrieving lsblk result twice Gabriel Goller
2024-09-17 8:05 ` Gabriel Goller [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240917080550.51803-2-g.goller@proxmox.com \
--to=g.goller@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox