Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use http/2 and keepalives #1378

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ leaky-bucket = { version = "0.12.1", optional = true }
libc = "0.2"
log = "0.4.8"
nix = "0.24"
reqwest = { version = "0.11.14", features = ["blocking", "json"], optional = true }
reqwest = { version = "0.11.14", features = ["blocking", "json", "rustls", "rustls-tls"], optional = true }
serde = { version = "1.0.110", features = ["serde_derive", "rc"] }
serde_json = "1.0.53"
sha1 = { version = "0.10.5", optional = true }
Expand Down
12 changes: 10 additions & 2 deletions storage/src/backend/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::str::FromStr;
use std::sync::atomic::{AtomicBool, AtomicI16, AtomicU8, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use std::{fmt, thread};
use std::{env, fmt, thread};

use log::{max_level, Level};

Expand Down Expand Up @@ -607,11 +607,19 @@ impl Connection {
} else {
None
};
// get pool size from envvar
let pool_max_idle_per_host = match env::var("REGISTRY_CLIENT_POOL_MAX_IDLE_PER_HOST") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these idle connections take pressure on the registry server? Especially when the container is started and prefetch work is done. Maybe we can make the value as the one option of ConnectionConfig.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would make a significant impact for reasonable values. Most servers should close idle connections if it becomes a problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the value as the one option of ConnectionConfig?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to fetch REGISTRY_CLIENT_POOL_MAX_IDLE_PER_HOST from configuration.

Ok(val) => val.parse::<usize>().unwrap_or(20),
Err(_) => 20,
};

let mut cb = Client::builder()
.timeout(timeout)
.connect_timeout(connect_timeout)
.redirect(Policy::none());
.redirect(Policy::none())
.use_rustls_tls()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use_rustls_tls() here? It introduces heavy dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using native-tls instead? We already have vendored openssl-sys crate.

openssl = { version = "0.10.55", features = ["vendored"] }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's required for http/2, as far as I know native-tls does not provide for the ALPN required for http/2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this be acceptable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be acceptable I think.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make any other changes to this then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the env REGISTRY_CLIENT_POOL_MAX_IDLE_PER_HOST value as the one option of ConnectionConfig?

.tcp_keepalive(Some(Duration::from_secs(5 * 60)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be configurable.

.pool_max_idle_per_host(pool_max_idle_per_host);

if config.skip_verify {
cb = cb.danger_accept_invalid_certs(true);
Expand Down
15 changes: 11 additions & 4 deletions storage/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,17 @@ pub trait BlobCache: Send + Sync {
)));
}
let duration = Instant::now().duration_since(start).as_millis();
let duration_s = duration as f64 / 1000.0;
let throughput_mbps = blob_size as f64 / duration_s / 1_000_000.0;

debug!(
"read_chunks_from_backend: {} {} {} bytes at {}, duration {}ms",
"read_chunks_from_backend: {} {} {} bytes at {}, duration {}ms, throughput {:.4}Mbps",
std::thread::current().name().unwrap_or_default(),
if prefetch { "prefetch" } else { "fetch" },
blob_size,
blob_offset,
duration
duration,
throughput_mbps
);

let chunks = chunks.iter().map(|v| v.as_ref()).collect();
Expand Down Expand Up @@ -328,12 +332,15 @@ pub trait BlobCache: Send + Sync {
}

let duration = Instant::now().duration_since(start).as_millis();
let duration_s = duration as f64 / 1000.0;
let throughput_mbps = chunk.compressed_size() as f64 / duration_s / 1_000_000.0;
debug!(
"read_chunk_from_backend: {} {} bytes at {}, duration {}ms",
"read_chunk_from_backend: {} {} bytes at {}, duration {}ms, throughput {:.4}Mbps",
std::thread::current().name().unwrap_or_default(),
chunk.compressed_size(),
chunk.compressed_offset(),
duration
duration,
throughput_mbps
);
self.validate_chunk_data(chunk, buffer, false)
.map_err(|e| {
Expand Down