From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E707165D12 for ; Fri, 24 Jul 2020 14:37:12 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DB587AAAA for ; Fri, 24 Jul 2020 14:37:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 12321AA9D for ; Fri, 24 Jul 2020 14:37:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CDF884329A for ; Fri, 24 Jul 2020 14:37:11 +0200 (CEST) To: Dietmar Maurer , Proxmox Backup Server development discussion References: <20200724081601.30073-1-t.lamprecht@proxmox.com> <808935848.14.1595592100554@webmail.proxmox.com> From: Thomas Lamprecht Message-ID: <6ed9997e-d2f4-9b9f-2615-5961fda2b90c@proxmox.com> Date: Fri, 24 Jul 2020 14:37:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <808935848.14.1595592100554@webmail.proxmox.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.177 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.344 Looks like a legit reply (A) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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] Subject: Re: [pbs-devel] applied: [PATCH backup 1/2] client: avoid division by zero in avg speed calculation, be more accurate 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: , X-List-Received-Date: Fri, 24 Jul 2020 12:37:13 -0000 Am 7/24/20 um 2:01 PM schrieb Dietmar Maurer: > Why don't you use a single duration.as_secs_f64() and compute speed using floting point? > Because usize -> f64 is a loss of precision and mainly this is moving back to exactly how you used to do: https://git.proxmox.com/?p=proxmox-backup.git;a=commitdiff;h=82ab72304efd651d2afa771c499d4bcec2787f64 thought you had similar/some reasons... And HumanByte has no from yet so either adding that or casting back would be required, but sure, have no hard feelings between: ... = ((uploaded as f64 / duration.as_secs_f64()) as usize).into() vs.: ... = ((uploaded * 1_000_000) / (duration.as_micros() as usize)).into(); >> On 07/24/2020 10:16 AM Thomas Lamprecht wrote: >> >> >> using micros vs. as_secs_f64 allows to have it calculated as usize >> bytes, easier to handle - this was also used when it still lived in >> upload_chunk_info_stream >> >> Co-authored-by: Stoiko Ivanov >> Signed-off-by: Thomas Lamprecht >> --- >> src/client/backup_writer.rs | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/src/client/backup_writer.rs b/src/client/backup_writer.rs >> index 7e5adb3..2344045 100644 >> --- a/src/client/backup_writer.rs >> +++ b/src/client/backup_writer.rs >> @@ -264,7 +264,7 @@ impl BackupWriter { >> crate::tools::format::strip_server_file_expenstion(archive_name.clone()) >> }; >> if archive_name != CATALOG_NAME { >> - let speed: HumanByte = (uploaded / (duration.as_secs() as usize)).into(); >> + let speed: HumanByte = ((uploaded * 1_000_000) / (duration.as_micros() as usize)).into(); >> let uploaded: HumanByte = uploaded.into(); >> println!("{}: had to upload {} from {} in {}s, avgerage speed {}/s).", archive, uploaded, vsize_h, duration.as_secs(), speed); >> } else { >> -- >> 2.27.0