Skip to content

Commit

Permalink
refactor: Use global http client to share the connection pool (#16276)
Browse files Browse the repository at this point in the history
refactor: Use global request client to share the connection pool

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Aug 19, 2024
1 parent 0368216 commit e14003c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/common/storage/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ use crate::StorageConfig;
static GLOBAL_HICKORY_RESOLVER: LazyLock<Arc<HickoryResolver>> =
LazyLock::new(|| Arc::new(HickoryResolver::default()));

static GLOBAL_HTTP_CLIENT: LazyLock<HttpClient> = LazyLock::new(|| {
new_storage_http_client().unwrap_or_else(|err| {
panic!("http client must be created successfully, but failed for {err}")
})
});

/// init_operator will init an opendal operator based on storage config.
pub fn init_operator(cfg: &StorageParams) -> Result<Operator> {
let op = match &cfg {
Expand Down Expand Up @@ -162,7 +168,7 @@ pub fn init_azblob_operator(cfg: &StorageAzblobConfig) -> Result<impl Builder> {
// Credential
.account_name(&cfg.account_name)
.account_key(&cfg.account_key)
.http_client(new_storage_http_client()?);
.http_client(GLOBAL_HTTP_CLIENT.clone());

Ok(builder)
}
Expand All @@ -187,7 +193,7 @@ fn init_gcs_operator(cfg: &StorageGcsConfig) -> Result<impl Builder> {
.bucket(&cfg.bucket)
.root(&cfg.root)
.credential(&cfg.credential)
.http_client(new_storage_http_client()?);
.http_client(GLOBAL_HTTP_CLIENT.clone());

Ok(builder)
}
Expand Down Expand Up @@ -284,7 +290,7 @@ fn init_s3_operator(cfg: &StorageS3Config) -> Result<impl Builder> {
builder = builder.enable_virtual_host_style();
}

builder = builder.http_client(new_storage_http_client()?);
builder = builder.http_client(GLOBAL_HTTP_CLIENT.clone());

Ok(builder)
}
Expand All @@ -301,7 +307,7 @@ fn init_obs_operator(cfg: &StorageObsConfig) -> Result<impl Builder> {
// Credential
.access_key_id(&cfg.access_key_id)
.secret_access_key(&cfg.secret_access_key)
.http_client(new_storage_http_client()?);
.http_client(GLOBAL_HTTP_CLIENT.clone());

Ok(builder)
}
Expand All @@ -317,7 +323,7 @@ fn init_oss_operator(cfg: &StorageOssConfig) -> Result<impl Builder> {
.root(&cfg.root)
.server_side_encryption(&cfg.server_side_encryption)
.server_side_encryption_key_id(&cfg.server_side_encryption_key_id)
.http_client(new_storage_http_client()?);
.http_client(GLOBAL_HTTP_CLIENT.clone());

Ok(builder)
}
Expand Down Expand Up @@ -350,7 +356,7 @@ fn init_cos_operator(cfg: &StorageCosConfig) -> Result<impl Builder> {
.secret_key(&cfg.secret_key)
.bucket(&cfg.bucket)
.root(&cfg.root)
.http_client(new_storage_http_client()?);
.http_client(GLOBAL_HTTP_CLIENT.clone());

Ok(builder)
}
Expand Down

0 comments on commit e14003c

Please sign in to comment.