Pooling for Azure

This commit is contained in:
Arpad Müller
2024-11-21 02:01:14 +01:00
parent 2d6bf176a0
commit 0606fe9fed
3 changed files with 16 additions and 1 deletions

1
Cargo.lock generated
View File

@@ -4667,6 +4667,7 @@ dependencies = [
"once_cell",
"pin-project-lite",
"rand 0.8.5",
"reqwest 0.11.19",
"scopeguard",
"serde",
"serde_json",

View File

@@ -18,6 +18,7 @@ camino = { workspace = true, features = ["serde1"] }
humantime-serde.workspace = true
hyper = { workspace = true, features = ["client"] }
futures.workspace = true
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
serde.workspace = true
serde_json.workspace = true
tokio = { workspace = true, features = ["sync", "fs", "io-util"] }

View File

@@ -15,6 +15,8 @@ use std::time::SystemTime;
use super::REMOTE_STORAGE_PREFIX_SEPARATOR;
use anyhow::Result;
use azure_core::request_options::{IfMatchCondition, MaxResults, Metadata, Range};
use azure_core::HttpClient;
use azure_core::TransportOptions;
use azure_core::{Continuable, RetryOptions};
use azure_identity::DefaultAzureCredential;
use azure_storage::StorageCredentials;
@@ -71,7 +73,9 @@ impl AzureBlobStorage {
};
// we have an outer retry
let builder = ClientBuilder::new(account, credentials).retry(RetryOptions::none());
let builder = ClientBuilder::new(account, credentials)
.retry(RetryOptions::none())
.transport(TransportOptions::new(reqwest_client(true)));
let client = builder.container_client(azure_config.container_name.to_owned());
@@ -244,6 +248,15 @@ impl AzureBlobStorage {
}
}
fn reqwest_client(allow_idle_connections: bool) -> Arc<dyn HttpClient> {
let max_idle = if allow_idle_connections { 8 } else { 0 };
let client = reqwest::ClientBuilder::new()
.pool_max_idle_per_host(max_idle)
.build()
.expect("failed to build `reqwest` client");
Arc::new(client)
}
fn to_azure_metadata(metadata: StorageMetadata) -> Metadata {
let mut res = Metadata::new();
for (k, v) in metadata.0.into_iter() {