src/client/http_client.rs: increase h2 window size, set tcp nodelay option

To increase h2 download speed.
This commit is contained in:
Dietmar Maurer 2019-06-28 16:00:58 +02:00
parent 81a6ce6fde
commit fcf5dea56d

View File

@ -27,7 +27,6 @@ use super::merge_known_chunks::*;
use crate::backup::*; use crate::backup::*;
#[derive(Clone)] #[derive(Clone)]
struct AuthInfo { struct AuthInfo {
username: String, username: String,
@ -163,7 +162,7 @@ impl HttpClient {
builder.danger_accept_invalid_certs(true); builder.danger_accept_invalid_certs(true);
let tlsconnector = builder.build().unwrap(); let tlsconnector = builder.build().unwrap();
let mut httpc = hyper::client::HttpConnector::new(1); let mut httpc = hyper::client::HttpConnector::new(1);
//httpc.set_nodelay(true); // not sure if this help? httpc.set_nodelay(true); // important for h2 download performance!
httpc.enforce_http(false); // we want https... httpc.enforce_http(false); // we want https...
let mut https = hyper_tls::HttpsConnector::from((httpc, tlsconnector)); let mut https = hyper_tls::HttpsConnector::from((httpc, tlsconnector));
https.https_only(true); // force it! https.https_only(true); // force it!
@ -324,7 +323,14 @@ impl HttpClient {
} }
}) })
.and_then(|upgraded| { .and_then(|upgraded| {
h2::client::handshake(upgraded).map_err(Error::from) let window_size = 32*1024*1024; // max = (1 << 31) - 2
h2::client::Builder::new()
.max_frame_size(4*1024*1024)
.initial_window_size(window_size)
.initial_connection_window_size(window_size)
.handshake(upgraded)
.map_err(Error::from)
}) })
.and_then(|(h2, connection)| { .and_then(|(h2, connection)| {
let connection = connection let connection = connection
@ -451,6 +457,7 @@ impl HttpClient {
} }
#[derive(Clone)]
pub struct BackupReader { pub struct BackupReader {
h2: H2Client, h2: H2Client,
canceller: Option<Canceller>, canceller: Option<Canceller>,
@ -493,6 +500,16 @@ impl BackupReader {
self.h2.download(path, Some(param), output) self.h2.download(path, Some(param), output)
} }
pub fn download_chunk<W: Write>(
&self,
digest: &[u8; 32],
output: W,
) -> impl Future<Item=W, Error=Error> {
let path = "chunk";
let param = json!({ "digest": proxmox::tools::digest_to_hex(digest) });
self.h2.download(path, Some(param), output)
}
pub fn force_close(mut self) { pub fn force_close(mut self) {
if let Some(canceller) = self.canceller.take() { if let Some(canceller) = self.canceller.take() {
canceller.cancel(); canceller.cancel();