public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Nicolas Frey <n.frey@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v4 5/9] verify: determine the number of threads to use with {read, verify}-threads
Date: Thu, 13 Nov 2025 10:31:14 +0100	[thread overview]
Message-ID: <20251113093118.195229-9-n.frey@proxmox.com> (raw)
In-Reply-To: <20251113093118.195229-1-n.frey@proxmox.com>

use previously introduced {read,verify}-threads in API, where default
values match the ones of the schema definition.

Tested-by: Christian Ebner <c.ebner@proxmox.com>
Signed-off-by: Nicolas Frey <n.frey@proxmox.com>
---
 src/api2/admin/datastore.rs    | 14 +++++++++++++-
 src/api2/backup/environment.rs |  4 +++-
 src/backup/verify.rs           | 16 ++++++++++++++--
 src/server/verify_job.rs       |  7 ++++++-
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 2d70e997..044dfb57 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -46,6 +46,7 @@ use pbs_api_types::{
     IGNORE_VERIFIED_BACKUPS_SCHEMA, MAX_NAMESPACE_DEPTH, NS_MAX_DEPTH_SCHEMA, PRIV_DATASTORE_AUDIT,
     PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_PRUNE, PRIV_DATASTORE_READ,
     PRIV_DATASTORE_VERIFY, PRIV_SYS_MODIFY, UPID, UPID_SCHEMA, VERIFICATION_OUTDATED_AFTER_SCHEMA,
+    VERIFY_JOB_READ_THREADS_SCHEMA, VERIFY_JOB_VERIFY_THREADS_SCHEMA,
 };
 use pbs_client::pxar::{create_tar, create_zip};
 use pbs_config::CachedUserInfo;
@@ -675,6 +676,14 @@ pub async fn status(
                 schema: NS_MAX_DEPTH_SCHEMA,
                 optional: true,
             },
+            "read-threads": {
+                schema: VERIFY_JOB_READ_THREADS_SCHEMA,
+                optional: true,
+            },
+            "verify-threads": {
+                schema: VERIFY_JOB_VERIFY_THREADS_SCHEMA,
+                optional: true,
+            },
         },
     },
     returns: {
@@ -700,6 +709,8 @@ pub fn verify(
     ignore_verified: Option<bool>,
     outdated_after: Option<i64>,
     max_depth: Option<usize>,
+    read_threads: Option<usize>,
+    verify_threads: Option<usize>,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Value, Error> {
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
@@ -779,7 +790,8 @@ pub fn verify(
         auth_id.to_string(),
         to_stdout,
         move |worker| {
-            let verify_worker = VerifyWorker::new(worker.clone(), datastore)?;
+            let verify_worker =
+                VerifyWorker::new(worker.clone(), datastore, read_threads, verify_threads)?;
             let failed_dirs = if let Some(backup_dir) = backup_dir {
                 let mut res = Vec::new();
                 if !verify_worker.verify_backup_dir(
diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index 1b8e0e1d..bd9c5211 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -800,7 +800,9 @@ impl BackupEnvironment {
             move |worker| {
                 worker.log_message("Automatically verifying newly added snapshot");
 
-                let verify_worker = VerifyWorker::new(worker.clone(), datastore)?;
+                // FIXME: update once per-datastore read/verify settings
+                // are available to not use default amount of threads here
+                let verify_worker = VerifyWorker::new(worker.clone(), datastore, None, None)?;
                 if !verify_worker.verify_backup_dir_with_lock(
                     &backup_dir,
                     worker.upid().clone(),
diff --git a/src/backup/verify.rs b/src/backup/verify.rs
index 07d51dcf..734c7b30 100644
--- a/src/backup/verify.rs
+++ b/src/backup/verify.rs
@@ -32,6 +32,8 @@ pub struct VerifyWorker {
     verified_chunks: Arc<Mutex<HashSet<[u8; 32]>>>,
     corrupt_chunks: Arc<Mutex<HashSet<[u8; 32]>>>,
     backend: DatastoreBackend,
+    read_threads: usize,
+    verify_threads: usize,
 }
 
 struct IndexVerifyState {
@@ -67,6 +69,8 @@ impl VerifyWorker {
     pub fn new(
         worker: Arc<dyn WorkerTaskContext>,
         datastore: Arc<DataStore>,
+        read_threads: Option<usize>,
+        verify_threads: Option<usize>,
     ) -> Result<Self, Error> {
         let backend = datastore.backend()?;
         Ok(Self {
@@ -77,6 +81,8 @@ impl VerifyWorker {
             // start with 64 chunks since we assume there are few corrupt ones
             corrupt_chunks: Arc::new(Mutex::new(HashSet::with_capacity(64))),
             backend,
+            read_threads: read_threads.unwrap_or(1),
+            verify_threads: verify_threads.unwrap_or(4),
         })
     }
 
@@ -115,7 +121,7 @@ impl VerifyWorker {
             &self.verified_chunks,
         ));
 
-        let decoder_pool = ParallelHandler::new("verify chunk decoder", 4, {
+        let decoder_pool = ParallelHandler::new("verify chunk decoder", self.verify_threads, {
             let verify_state = Arc::clone(&verify_state);
             move |(chunk, digest, size): (DataBlob, [u8; 32], u64)| {
                 let chunk_crypt_mode = match chunk.crypt_mode() {
@@ -177,7 +183,7 @@ impl VerifyWorker {
             .datastore
             .get_chunks_in_order(&*index, skip_chunk, check_abort)?;
 
-        let reader_pool = ParallelHandler::new("read chunks", 1, {
+        let reader_pool = ParallelHandler::new("read chunks", self.read_threads, {
             let decoder_pool = decoder_pool.channel();
             let verify_state = Arc::clone(&verify_state);
             let backend = self.backend.clone();
@@ -585,6 +591,12 @@ impl VerifyWorker {
         let group_count = list.len();
         info!("found {group_count} groups");
 
+        log::info!(
+            "using {} read and {} verify thread(s)",
+            self.read_threads,
+            self.verify_threads,
+        );
+
         let mut progress = StoreProgress::new(group_count as u64);
 
         for (pos, group) in list.into_iter().enumerate() {
diff --git a/src/server/verify_job.rs b/src/server/verify_job.rs
index c8792174..e0b03155 100644
--- a/src/server/verify_job.rs
+++ b/src/server/verify_job.rs
@@ -41,7 +41,12 @@ pub fn do_verification_job(
                 None => Default::default(),
             };
 
-            let verify_worker = VerifyWorker::new(worker.clone(), datastore)?;
+            let verify_worker = VerifyWorker::new(
+                worker.clone(),
+                datastore,
+                verification_job.read_threads,
+                verification_job.verify_threads,
+            )?;
             let result = verify_worker.verify_all_backups(
                 worker.upid(),
                 ns,
-- 
2.47.3


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  parent reply	other threads:[~2025-11-13  9:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13  9:31 [pbs-devel] [PATCH proxmox{, -backup} v4 00/12] parallelize chunk reads in verification Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox v4 1/3] pbs-api-types: add schema for {worker, read, verify}-threads Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox v4 2/3] pbs-api-types: jobs: add {read, verify}-threads to VerificationJobConfig Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox v4 3/3] pbs-api-types: use worker-threads schema for TapeBackupJobSetup Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 1/9] verify: correct typo in comment Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 2/9] verify: introduce new state struct Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 3/9] verify: refactor into associated functions to use " Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 4/9] verify: move chunk loading into parallel handler Nicolas Frey
2025-11-13  9:31 ` Nicolas Frey [this message]
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 6/9] verify: add {read, verify}-threads to update endpoint Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 7/9] verify: add {read, verify}-threads to api schema in backup manager Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 8/9] ui: verify: add option to set number of threads for job Nicolas Frey
2025-11-13  9:31 ` [pbs-devel] [PATCH proxmox-backup v4 9/9] docs: verify: document {read, verify}-threads and update screenshot Nicolas Frey
2025-11-14 10:41   ` Christian Ebner
2025-11-13 12:53 ` [pbs-devel] [PATCH proxmox{, -backup} v4 00/12] parallelize chunk reads in verification Fabian Grünbichler
2025-11-14 10:46 ` Christian Ebner
2025-11-14 21:36 ` [pbs-devel] applied: " Thomas Lamprecht
2025-11-14 22:17 ` Thomas Lamprecht

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=20251113093118.195229-9-n.frey@proxmox.com \
    --to=n.frey@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal