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 792B61FF167 for ; Wed, 31 Jul 2024 11:36:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E651BAB16; Wed, 31 Jul 2024 11:36:08 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Wed, 31 Jul 2024 11:36:03 +0200 Message-Id: <20240731093604.1315088-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240731093604.1315088-1-d.csapak@proxmox.com> References: <20240731093604.1315088-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 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 Subject: [pbs-devel] [PATCH proxmox-backup v2 3/4] datastore: data blob: increase compression throughput 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" by not using `zstd::stream::copy_encode`, because that has an allocation pattern that reduces throughput if the target/source storage and the network are faster than the chunk creation. instead use `zstd::bulk::compress_to_buffer` which shouldn't do any big allocations, since we provide the target buffer. To handle the case that the target buffer is too small, we now ignore all zstd error and continue with the uncompressed data, logging the error except if the target buffer is too small. For now, we have to parse the error string for that, as `zstd` maps all errors as `io::ErrorKind::Other`. Until that gets changed, there is no other way to differentiate between different kind of errors. Signed-off-by: Dominik Csapak --- changes from v1: * fixed commit message * reduced log severity to `warn` * use vec![0; size] * omit unnecessary buffer allocation in the unencrypted,uncompressed case by reusing the initial buffer that was tried for compression pbs-datastore/src/data_blob.rs | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pbs-datastore/src/data_blob.rs b/pbs-datastore/src/data_blob.rs index 8715afef..2a528204 100644 --- a/pbs-datastore/src/data_blob.rs +++ b/pbs-datastore/src/data_blob.rs @@ -136,39 +136,44 @@ impl DataBlob { DataBlob { raw_data } } else { - let max_data_len = data.len() + std::mem::size_of::(); + let header_len = std::mem::size_of::(); + let max_data_len = data.len() + header_len; + let mut raw_data = vec![0; max_data_len]; if compress { - let mut comp_data = Vec::with_capacity(max_data_len); - let head = DataBlobHeader { magic: COMPRESSED_BLOB_MAGIC_1_0, crc: [0; 4], }; unsafe { - comp_data.write_le_value(head)?; + (&mut raw_data[0..header_len]).write_le_value(head)?; } - zstd::stream::copy_encode(data, &mut comp_data, 1)?; - - if comp_data.len() < max_data_len { - let mut blob = DataBlob { - raw_data: comp_data, - }; - blob.set_crc(blob.compute_crc()); - return Ok(blob); + match zstd::bulk::compress_to_buffer(data, &mut raw_data[header_len..], 1) { + Ok(size) if size <= data.len() => { + raw_data.truncate(header_len + size); + let mut blob = DataBlob { raw_data }; + blob.set_crc(blob.compute_crc()); + return Ok(blob); + } + // if size is bigger than the data, or any error is returned, continue with non + // compressed archive but log all errors beside buffer too small + Ok(_) => {} + Err(err) => { + if !err.to_string().contains("Destination buffer is too small") { + log::warn!("zstd compression error: {err}"); + } + } } } - let mut raw_data = Vec::with_capacity(max_data_len); - let head = DataBlobHeader { magic: UNCOMPRESSED_BLOB_MAGIC_1_0, crc: [0; 4], }; unsafe { - raw_data.write_le_value(head)?; + (&mut raw_data[0..header_len]).write_le_value(head)?; } - raw_data.extend_from_slice(data); + (&mut raw_data[header_len..]).write_all(data)?; DataBlob { raw_data } }; -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel