src/api2/reader.rs - download_chunk: use blocking io
Turns out to be twice as fast as tokio async io...
This commit is contained in:
		@ -221,6 +221,37 @@ fn download_chunk(
 | 
				
			|||||||
    rpcenv: Box<dyn RpcEnvironment>,
 | 
					    rpcenv: Box<dyn RpcEnvironment>,
 | 
				
			||||||
) -> Result<BoxFut, Error> {
 | 
					) -> Result<BoxFut, Error> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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<dyn RpcEnvironment>,
 | 
				
			||||||
 | 
					) -> Result<BoxFut, Error> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let env: &ReaderEnvironment = rpcenv.as_ref();
 | 
					    let env: &ReaderEnvironment = rpcenv.as_ref();
 | 
				
			||||||
    let env2 = env.clone();
 | 
					    let env2 = env.clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -251,6 +282,7 @@ fn download_chunk(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Ok(Box::new(response_future))
 | 
					    Ok(Box::new(response_future))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn api_method_speedtest() -> ApiAsyncMethod {
 | 
					pub fn api_method_speedtest() -> ApiAsyncMethod {
 | 
				
			||||||
    ApiAsyncMethod::new(
 | 
					    ApiAsyncMethod::new(
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user