[pbs-devel] [PATCH proxmox-backup 2/2] api: parallelize smartctl checks
Gabriel Goller
g.goller at proxmox.com
Mon Sep 16 16:56:27 CEST 2024
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 at 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(-)
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
More information about the pbs-devel
mailing list