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:
Dietmar Maurer 2019-10-05 11:41:19 +02:00
parent ff01c1e393
commit c0b1b14c05
1 changed files with 32 additions and 0 deletions

View File

@ -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(&param, "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(