From c0b1b14c050d52ec6d2d4f47d16e553bdc8280fc Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 5 Oct 2019 11:41:19 +0200 Subject: [PATCH] src/api2/reader.rs - download_chunk: use blocking io Turns out to be twice as fast as tokio async io... --- src/api2/reader.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/api2/reader.rs b/src/api2/reader.rs index 99a245cf..0f721d97 100644 --- a/src/api2/reader.rs +++ b/src/api2/reader.rs @@ -221,6 +221,37 @@ fn download_chunk( rpcenv: Box, ) -> Result { + let env: &ReaderEnvironment = rpcenv.as_ref(); + + let digest_str = tools::required_string_param(¶m, "digest")?; + let digest = proxmox::tools::hex_to_digest(digest_str)?; + + let (path, _) = env.datastore.chunk_path(&digest); + + env.debug(format!("download chunk {:?}", path)); + + let data = proxmox::tools::fs::file_get_contents(&path)?; // todo: blocking() + let body = Body::from(data); + + // fixme: set other headers ? + Ok(Box::new(futures::future::ok( + Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "application/octet-stream") + .body(body) + .unwrap()) + )) +} + +/* this is too slow +fn download_chunk_old( + _parts: Parts, + _req_body: Body, + param: Value, + _info: &ApiAsyncMethod, + rpcenv: Box, +) -> Result { + let env: &ReaderEnvironment = rpcenv.as_ref(); let env2 = env.clone(); @@ -251,6 +282,7 @@ fn download_chunk( Ok(Box::new(response_future)) } +*/ pub fn api_method_speedtest() -> ApiAsyncMethod { ApiAsyncMethod::new(