From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 2/3] s3-client: dynamically calculate put request timeout based on payload
Date: Wed, 20 Aug 2025 11:58:04 +0200 [thread overview]
Message-ID: <20250820095807.172722-3-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250820095807.172722-1-c.ebner@proxmox.com>
The request-response time for uploading objects to the S3 API via
put_object call depends on the size of the payload to be transferred.
The current default of 60 seconds might not be enough to upload
chunks or blobs in case of low available upload bandwidth.
Blobs are currently the largest objects which can be uploaded
to the PBS API, reaching up to 128 MiB [0]. Other files such as
notes and index files are typically smaller.
To allow uploads over low upload bandwidth connections to S3 as well,
expose the optional timeout for the put object method and calculate
it dynamically, based on the size of the to be uploaded request
payload assuming a minimum average upload rate of 1KiB/s. However,
keep the default value as minimum timeout.
[0] https://git.proxmox.com/?p=proxmox-backup.git;a=blob;f=pbs-datastore/src/data_blob.rs;h=0c05c5a40ae67d4a0d7847817102f30de1df3933;hb=HEAD#l13
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
proxmox-s3-client/examples/s3_client.rs | 3 ++-
proxmox-s3-client/src/client.rs | 15 +++++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/proxmox-s3-client/examples/s3_client.rs b/proxmox-s3-client/examples/s3_client.rs
index 61b88077..67baf467 100644
--- a/proxmox-s3-client/examples/s3_client.rs
+++ b/proxmox-s3-client/examples/s3_client.rs
@@ -50,8 +50,9 @@ async fn run() -> Result<(), anyhow::Error> {
let rel_object_key = S3ObjectKey::try_from("object.txt")?;
let body = proxmox_http::Body::empty();
let replace_existing_key = true;
+ let request_timeout = Some(std::time::Duration::from_secs(60));
let _response = s3_client
- .put_object(rel_object_key, body, replace_existing_key)
+ .put_object(rel_object_key, body, request_timeout, replace_existing_key)
.await?;
// List object, limiting to ones matching the given prefix. Since the api limits the response
diff --git a/proxmox-s3-client/src/client.rs b/proxmox-s3-client/src/client.rs
index 2a48240e..8a551f3a 100644
--- a/proxmox-s3-client/src/client.rs
+++ b/proxmox-s3-client/src/client.rs
@@ -35,6 +35,8 @@ const S3_HTTP_CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
const S3_HTTP_REQUEST_TIMEOUT: Duration = Duration::from_secs(60);
const S3_TCP_KEEPALIVE_TIME: u32 = 120;
const MAX_S3_UPLOAD_RETRY: usize = 3;
+// Assumed minimum upload rate of 1 KiB/s for dynamic put object request timeout calculation.
+const S3_MIN_ASSUMED_UPLOAD_RATE: u64 = 1024;
/// S3 object key path prefix without the context prefix as defined by the client options.
///
@@ -413,6 +415,7 @@ impl S3Client {
&self,
object_key: S3ObjectKey,
object_data: Body,
+ timeout: Option<Duration>,
replace: bool,
) -> Result<PutObjectResponse, Error> {
let object_key = object_key.to_full_key(&self.options.common_prefix);
@@ -435,7 +438,7 @@ impl S3Client {
let request = request.body(object_data)?;
- let response = self.send(request, Some(S3_HTTP_REQUEST_TIMEOUT)).await?;
+ let response = self.send(request, timeout).await?;
let response_reader = ResponseReader::new(response);
response_reader.put_object_response().await
}
@@ -664,9 +667,17 @@ impl S3Client {
object_data: Bytes,
replace: bool,
) -> Result<bool, Error> {
+ let content_size = object_data.len() as u64;
+ let timeout_secs = content_size
+ .div_ceil(S3_MIN_ASSUMED_UPLOAD_RATE)
+ .max(S3_HTTP_REQUEST_TIMEOUT.as_secs());
+ let timeout = Some(Duration::from_secs(timeout_secs));
for retry in 0..MAX_S3_UPLOAD_RETRY {
let body = Body::from(object_data.clone());
- match self.put_object(object_key.clone(), body, replace).await {
+ match self
+ .put_object(object_key.clone(), body, timeout, replace)
+ .await
+ {
Ok(PutObjectResponse::Success(_response_body)) => return Ok(false),
Ok(PutObjectResponse::PreconditionFailed) => return Ok(true),
Ok(PutObjectResponse::NeedsRetry) => {
--
2.47.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-08-20 9:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 9:58 [pbs-devel] [PATCH proxmox{, -backup} 0/5] dynamically calculate request timeout for put object calls Christian Ebner
2025-08-20 9:58 ` [pbs-devel] [PATCH proxmox 1/3] s3-client: allow setting custom timeout when sending requests Christian Ebner
2025-08-20 9:58 ` Christian Ebner [this message]
2025-08-20 9:58 ` [pbs-devel] [PATCH proxmox 3/3] s3-client: expose default timeout for s3 api requests Christian Ebner
2025-08-20 9:58 ` [pbs-devel] [PATCH proxmox-backup 1/2] s3: pass now optional default request timeout for s3 api calls Christian Ebner
2025-08-20 9:58 ` [pbs-devel] [PATCH proxmox-backup 2/2] api: format error to show full context for failed chunk uploads Christian Ebner
2025-08-25 9:35 ` [pbs-devel] applied-series: [PATCH proxmox{, -backup} 0/5] dynamically calculate request timeout for put object calls Wolfgang Bumiller
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=20250820095807.172722-3-c.ebner@proxmox.com \
--to=c.ebner@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