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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 94E1568D9B for ; Fri, 4 Dec 2020 15:15:12 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 81E38ACE9 for ; Fri, 4 Dec 2020 15:14:42 +0100 (CET) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40084.outbound.protection.outlook.com [40.107.4.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 87741ACDF for ; Fri, 4 Dec 2020 15:14:40 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a5mrYOXJOFBKd9d0xnzH+h+iDVDePaCP/FdXWnsKsypKdcbMyTiPcFDyYWdh+hkIUR6eIKnsLMbaulZVUB+yk83jM1TxgUn5PaD260E66vvWP9IDqmUUN2Q40JpzR7cajNnmRmdgwCg2bczRusShM9sqg/qKIshIh7K+nlQi1oMRy0KBKmRMjsoFJ38Wcauh7naEFJ0r+Rbx4AbQuj5+Rt81HHE946qNIH3b4EaChoSjYBb3dLz6ldFjsmCRH0aa8f4jVUM7GaSmvH2Irzae0xcdHvlCFG0LUnGQAWHD0un2tQE7NzolTHjZyg7VpVSgSvuwr4G2qdeXhyOAIv/INA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xL3slxEoiwww+3F+W1x436jfaUbWs8Li0yYzQTi0FEY=; b=ZGUoEQyN9XGH6GoTycJibarot100VDMyg5J/UuhmBW2jWltbfKzYRDb6cKZ0NZgFQSEGcRgyL850/SEHQhGqHWicBnJNWty/PRg6do2GzE1KjNJ42b+U7S9R8T5RR03i/AcDxcuiU5AkXWLUmctp5A15L6v8tJpM3FoDGfsZ/wVJ1mGOdtrSlqK66NY2MhrEnr6r8TlQcd0zff/RqS4n7A7AXhpGKMkBjzJkAvWoCyFrws8yCawW21uiwm5KvWMTUsnrA0calX8e2g3zlwFMX4gZ57Izj12i48EP7XQ8proVXDSXnJnGGzjvBP5BClk/YTwdxBHKYAhnAJ7SiT4bFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=logics.de; dmarc=pass action=none header.from=logics.de; dkim=pass header.d=logics.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=logics99.onmicrosoft.com; s=selector2-logics99-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xL3slxEoiwww+3F+W1x436jfaUbWs8Li0yYzQTi0FEY=; b=RVoa4L7c4Q+xw68ON8+ceF0gnaz4ECeP7zOtHd7sr3r3AbIxeFreJ0i4NHHKqT40tB/wZd2SUziXzYniDcllBG1B9zp/uQBYwtwC2u0a3KQEOr8SLEsfTrF/+p4kJREYBF5f20BB72Ndy5re+z/M+cBFjVIqbO6WAfWjMeTLo/o= Received: from AM0PR09MB2754.eurprd09.prod.outlook.com (2603:10a6:208:12e::18) by AM9PR09MB4833.eurprd09.prod.outlook.com (2603:10a6:20b:2d9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Fri, 4 Dec 2020 14:14:33 +0000 Received: from AM0PR09MB2754.eurprd09.prod.outlook.com ([fe80::68c5:8966:920c:8d24]) by AM0PR09MB2754.eurprd09.prod.outlook.com ([fe80::68c5:8966:920c:8d24%3]) with mapi id 15.20.3632.021; Fri, 4 Dec 2020 14:14:33 +0000 From: Niko Fellner To: "pbs-devel@lists.proxmox.com" Thread-Topic: parallelize restore.rs fn restore_image: problems in async move Thread-Index: AdbKR5NQuUK4YTZbRJ+mjP9LatDx2Q== Date: Fri, 4 Dec 2020 14:14:33 +0000 Message-ID: Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: lists.proxmox.com; dkim=none (message not signed) header.d=none;lists.proxmox.com; dmarc=none action=none header.from=logics.de; x-originating-ip: [80.81.12.137] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 29fbd990-9c36-47b1-83c9-08d8985eeca2 x-ms-traffictypediagnostic: AM9PR09MB4833: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vRc3ZfDtmsi4i3as+hyhVfWC/MnwJdW/udsvMXJO/nddVs1hXaVfgpRjG31PgQ9TGLtlA1gUHou81LxsvSGRm991qE2p+BrJcgwx+2fAHTW/aZ5t8aej+xKosu4TNkF/JUieIB9Mw3k57NAR4G6ve+u1Gene6d2nXeG1WkF17Q8mqzmnJ3/uWVbr2swsn66jpYfYq+VpTu3yuViH8A6WW+HcokRe79V+Pw+jmx3AzKLxjsFdOPPmZ4+KoAlz2W6KQtyWC0/DdyyQ309KDSbO4QYDqJ55EQJEsOH2ks3VGuTL2ka3k9xbsAITVvMgYyfWmM59S07H5bJZEAQxrLnEWVMjFfeFtn5AQAKPc4QWUsSEYsIQcFAo3KXuJF+XjTw+1bHHkaKn/owtTKehONwD6g== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR09MB2754.eurprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39830400003)(376002)(136003)(346002)(366004)(316002)(71200400001)(26005)(86362001)(966005)(6506007)(8936002)(83380400001)(9686003)(76116006)(7696005)(66946007)(52536014)(2906002)(6916009)(66476007)(186003)(478600001)(5660300002)(55016002)(33656002)(8676002)(66446008)(66556008)(64756008); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?7DgePI6DTCKNAtSNDP2TRV8A5ilJHnaUwmJ0Ii+MwqNvF2zhgu0KABE39yvu?= =?us-ascii?Q?CmHMFPRuUE23ViOQQ6B+jMuYOfCLTdej5S1bKn92NFJ9nKITBMz8nPUIMXxH?= =?us-ascii?Q?/yW8dBUgY/uBJ3n4a/0dS8xvs02+aDZN6weYYDmo3PeYfBK0eNVDyDqeXKHY?= =?us-ascii?Q?a5XRDe0DWQsRTEw8nkNFjAKQY9rz3OxMnFUcOAHxCldIKcG39CmUL+1MIO5B?= =?us-ascii?Q?snLd4VHsVL+Yi5yfdYF5gyquhF+kJCA+U2SnOqhPoW6T+GvaVqBn8K8MZwqP?= =?us-ascii?Q?5J/2qtMTGbH7sU8q2MQ3+81CjCt6Vhh8U/DDNC5bLw6X4oHSEmITpqRRrWqh?= =?us-ascii?Q?BqqzDjt+FHEFi2cltIAiWLMtOz/lp+V/SPr5cHnXPhzXnwe/NaDsiY5IiQDg?= =?us-ascii?Q?xn63NgR3JLGiLoJ6o5h7yx1BfloBZPce6ATTlrIIUgQlYt6Xz29o0RrzF4y3?= =?us-ascii?Q?i81+ZYdmJJ+Rj819bS9isqwnlHKV+p/voIbbwU64cxTz/bwiMRijtufVlrCx?= =?us-ascii?Q?GbyuyHUFhXif9eXx98v8NuYBmrYERZSZmPYhZAdKEq/1U/rVRX/SbLPsBp9W?= =?us-ascii?Q?mPp2qoFb+H2t/g7X/mnk/RGoWklgV/t3Waxdjh0HfOu5CI6SqKa1RVOSBhMM?= =?us-ascii?Q?ZwtP1UGpJMBvlPYAGoTR5i2HlsckfH0jqw4d5hJ03XbaYStjBPlWl4MlWMTL?= =?us-ascii?Q?FoepgfkTX1Vj+D0w4x8NeWp+R0D+oed4aWBylNrf1+yhwQCfv8zy+5dm1nvH?= =?us-ascii?Q?1ID/cDf1o5Et0QPTuFvp5X1dmDsvjdfSQCbrZyEXSNf0Qs3KxH2zacxEoD3n?= =?us-ascii?Q?Z6LIvuttV4lu4mQhllGZ1LOMXbzhkoNA+PkewPJ9IyhI1zE6taoeCEWo10B1?= =?us-ascii?Q?VbejQSwXaDR1S6fgs8s9zhNsCxGx+oTNwS/apdBTooYl/4PjR1ob2UHeSH1r?= =?us-ascii?Q?09H2KwM8UxdVS/BufHPeS+m0T2sh1zWu+Tf7LP8S06c=3D?= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: logics.de X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM0PR09MB2754.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29fbd990-9c36-47b1-83c9-08d8985eeca2 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Dec 2020 14:14:33.6556 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: fdfa9215-653f-430f-b8ab-a8728140f97a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 8nBEeGspPmnrZ26GMJCmG4RQNM2CL/oPhqKQu6XSLcXvxYdMz/f2OqIi3o2NnXB492uWu1/fh/h7gzrqd5Uwcw7pSZYf13eK8QInP+my8Rw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR09MB4833 X-SPAM-LEVEL: Spam detection results: 0 DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature KAM_ASCII_DIVIDERS 0.8 Spam that uses ascii formatting tricks RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust RCVD_IN_MSPIKE_H2 -0.001 Average reputation (+2) SPF_HELO_PASS -0.001 SPF: HELO matches 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. [logics99.onmicrosoft.com, proxmox.com, restore.rs] Subject: [pbs-devel] parallelize restore.rs fn restore_image: problems in async move 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, 04 Dec 2020 14:15:12 -0000 In order to parallelize restore_image within restore.rs (#3163), I tried to= make use of tokio: let mut my_handles =3D vec![]; for pos in 0..100 { my_handles.push( tokio::spawn( async move { println!("Task: {}", pos) } ) ); } futures::future::join_all(my_handles).await; This simple code works and prints all tasks (in some random order), but whe= n I change the body of the "async move" to the original loop body in restor= e_image, I get some build errors: cargo build --release Compiling proxmox-backup-qemu v1.0.2 (/root/proxmox-backup-qemu) error[E0308]: mismatched types --> src/restore.rs:181:48 | 181 | ... if per !=3D next_per { | __________________________________________^ 182 | | ... eprintln!("progress {}% (read {} bytes, z= eroes =3D {}% ({} bytes), duration {} sec)", 183 | | ... next_per, bytes, 184 | | ... zeroes*100/bytes, zeroes, 185 | | ... start_time.elapsed().as_secs())= ; 186 | | ... per =3D next_per; 187 | | ... } | |_______________________^ expected enum `std::result::Result`, found = `()` | =3D note: expected enum `std::result::Result<_, anyhow::Error>` found unit type `()` error[E0308]: mismatched types --> src/restore.rs:181:29 | 181 | / ... if per !=3D next_per { 182 | | ... eprintln!("progress {}% (read {} bytes, z= eroes =3D {}% ({} bytes), duration {} sec)", 183 | | ... next_per, bytes, 184 | | ... zeroes*100/bytes, zeroes, 185 | | ... start_time.elapsed().as_secs())= ; 186 | | ... per =3D next_per; 187 | | ... } | |_______________________^ expected enum `std::result::Result`, found = `()` | =3D note: expected enum `std::result::Result<_, anyhow::Error>` found unit type `()` error[E0308]: mismatched types --> src/restore.rs:179:25 | 179 | / if verbose { 180 | | let next_per =3D ((pos+1)*100)/index.in= dex_count(); 181 | | if per !=3D next_per { 182 | | eprintln!("progress {}% (read {} by= tes, zeroes =3D {}% ({} bytes), duration {} sec)", ... | 187 | | } 188 | | } | |_________________________^ expected enum `std::result::Result`, foun= d `()` | =3D note: expected enum `std::result::Result<_, anyhow::Error>` found unit type `()` error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. error: could not compile `proxmox-backup-qemu`. To learn more, run the command again with --verbose. make: *** [Makefile:22: all] Fehler 101 Do you have any clue how to fix this? I guess I am doing rookie mistakes. Another question: Do you think it's easier to use rayon here instead of tok= io to find out whether parallelization is worth it here or not?=20 The rayon::iter::ParallelIterator looks promising, but I realized the rayon= 1.5 lib is not included in http://download.proxmox.com/debian/devel/ curre= ntly... diff --git a/Cargo.toml b/Cargo.toml index 7f29d0a..c87bf5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,9 +27,9 @@ lazy_static =3D "1.4" libc =3D "0.2" once_cell =3D "1.3.1" openssl =3D "0.10" -proxmox =3D { version =3D "0.7.0", features =3D [ "sortable-macro", "api-m= acro" ] } -proxmox-backup =3D { git =3D "git://git.proxmox.com/git/proxmox-backup.git= ", tag =3D "v1.0.4" } -#proxmox-backup =3D { path =3D "../proxmox-backup" } +proxmox =3D { version =3D "0.8.0", features =3D [ "sortable-macro", "api-m= acro" ] } +#proxmox-backup =3D { git =3D "git://git.proxmox.com/git/proxmox-backup.gi= t", tag =3D "v1.0.4" } +proxmox-backup =3D { path =3D "../proxmox-backup" } serde_json =3D "1.0" tokio =3D { version =3D "0.2.9", features =3D [ "blocking", "fs", "io-util= ", "macros", "rt-threaded", "signal", "stream", "tcp", "time", "uds" ] } bincode =3D "1.0" diff --git a/src/restore.rs b/src/restore.rs index 24983dd..4d1df9c 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -151,38 +151,46 @@ impl RestoreTask { let mut per =3D 0; let mut bytes =3D 0; let mut zeroes =3D 0; + let mut my_handles =3D vec![]; =20 let start_time =3D std::time::Instant::now(); =20 for pos in 0..index.index_count() { - let digest =3D index.index_digest(pos).unwrap(); - let offset =3D (pos*index.chunk_size) as u64; - if digest =3D=3D &zero_chunk_digest { - let res =3D write_zero_callback(offset, index.chunk_size a= s u64); - if res < 0 { - bail!("write_zero_callback failed ({})", res); - } - bytes +=3D index.chunk_size; - zeroes +=3D index.chunk_size; - } else { - let raw_data =3D ReadChunk::read_chunk(&chunk_reader, &dig= est)?; - let res =3D write_data_callback(offset, &raw_data); - if res < 0 { - bail!("write_data_callback failed ({})", res); - } - bytes +=3D raw_data.len(); - } - if verbose { - let next_per =3D ((pos+1)*100)/index.index_count(); - if per !=3D next_per { - eprintln!("progress {}% (read {} bytes, zeroes =3D {}%= ({} bytes), duration {} sec)", - next_per, bytes, - zeroes*100/bytes, zeroes, - start_time.elapsed().as_secs()); - per =3D next_per; - } - } + my_handles.push( + tokio::spawn( + async move { + let digest =3D index.index_digest(pos).unwrap(); + let offset =3D (pos*index.chunk_size) as u64; + if digest =3D=3D &zero_chunk_digest { + let res =3D write_zero_callback(offset, index.= chunk_size as u64); + if res < 0 { + bail!("write_zero_callback failed ({})", r= es); + } + bytes +=3D index.chunk_size; + zeroes +=3D index.chunk_size; + } else { + let raw_data =3D ReadChunk::read_chunk(&chunk_= reader, &digest)?; + let res =3D write_data_callback(offset, &raw_d= ata); + if res < 0 { + bail!("write_data_callback failed ({})", r= es); + } + bytes +=3D raw_data.len(); + } + if verbose { + let next_per =3D ((pos+1)*100)/index.index_cou= nt(); + if per !=3D next_per { + eprintln!("progress {}% (read {} bytes, ze= roes =3D {}% ({} bytes), duration {} sec)", + next_per, bytes, + zeroes*100/bytes, zeroes, + start_time.elapsed().as_secs()); + per =3D next_per; + } + } + } + ) + ); } + futures::future::join_all(my_handles).await; =20 let end_time =3D std::time::Instant::now(); let elapsed =3D end_time.duration_since(start_time);