public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Robert Obkircher <r.obkircher@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH v1 proxmox-backup] api: do not block tokio worker threads during chunk inserts
Date: Wed, 27 May 2026 14:37:51 +0200	[thread overview]
Message-ID: <20260527123809.238964-1-r.obkircher@proxmox.com> (raw)

Move synchronous operations off the worker threads to prevent blocking
the I/O and timer drivers of the entire runtime. This is especially
important for S3 uploads, which wait up to 3 hours for the chunk lock.

Also prevent worker starvation, which could happen because S3 uploads
are wrapped in proxmox_async::runtime::block_on, which prevents other
futures from running in the current thread.

In the backtrace from the linked forum post, two workers were waiting
for chunk locks (presumably due to duplicates) while the remaining 19
were stuck because block_on called std::thread::park.

Fixes: https://forum.proxmox.com/threads/183705
Signed-off-by: Robert Obkircher <r.obkircher@proxmox.com>
---
 src/api2/backup/upload_chunk.rs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/api2/backup/upload_chunk.rs b/src/api2/backup/upload_chunk.rs
index 59e4caee2..eec24add2 100644
--- a/src/api2/backup/upload_chunk.rs
+++ b/src/api2/backup/upload_chunk.rs
@@ -1,4 +1,5 @@
 use std::pin::Pin;
+use std::sync::Arc;
 use std::task::{Context, Poll};
 
 use anyhow::{Error, bail, format_err};
@@ -8,6 +9,7 @@ use http_body_util::{BodyDataStream, BodyExt};
 use hyper::body::Incoming;
 use hyper::http::request::Parts;
 use serde_json::{Value, json};
+use tokio::task::spawn_blocking;
 
 use proxmox_router::{ApiHandler, ApiMethod, ApiResponseFuture, RpcEnvironment};
 use proxmox_schema::*;
@@ -232,14 +234,18 @@ async fn upload_to_backend(
     let (digest, size, chunk) =
         UploadChunk::new(BodyDataStream::new(req_body), digest, size, encoded_size).await?;
 
+    let datastore = Arc::clone(&env.datastore);
+    let backend = env.backend.clone();
+
     if env.no_cache {
         let (is_duplicate, chunk_size) =
-            env.datastore
-                .insert_chunk_no_cache(&chunk, &digest, &env.backend)?;
+            spawn_blocking(move || datastore.insert_chunk_no_cache(&chunk, &digest, &backend))
+                .await??;
         return Ok((digest, size, chunk_size as u32, is_duplicate));
     }
 
-    let (is_duplicate, chunk_size) = env.datastore.insert_chunk(&chunk, &digest, &env.backend)?;
+    let (is_duplicate, chunk_size) =
+        spawn_blocking(move || datastore.insert_chunk(&chunk, &digest, &backend)).await??;
     Ok((digest, size, chunk_size as u32, is_duplicate))
 }
 
-- 
2.47.3





             reply	other threads:[~2026-05-27 12:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27 12:37 Robert Obkircher [this message]
2026-05-27 16:12 ` [PATCH v1 proxmox-backup] api: do not block tokio worker threads during chunk inserts Christian Ebner
2026-05-29 10:22 ` applied: " 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=20260527123809.238964-1-r.obkircher@proxmox.com \
    --to=r.obkircher@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