From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id EFDE21FF17C for ; Wed, 20 Aug 2025 11:57:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BFAD8376EE; Wed, 20 Aug 2025 11:58:53 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 20 Aug 2025 11:58:04 +0200 Message-ID: <20250820095807.172722-3-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250820095807.172722-1-c.ebner@proxmox.com> References: <20250820095807.172722-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1755683855461 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.042 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, client.rs] Subject: [pbs-devel] [PATCH proxmox 2/3] s3-client: dynamically calculate put request timeout based on payload X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" 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 --- 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, replace: bool, ) -> Result { 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 { + 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