Skip to content

Commit e14003c

Browse files
authored
refactor: Use global http client to share the connection pool (#16276)
refactor: Use global request client to share the connection pool Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent 0368216 commit e14003c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/common/storage/src/operator.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ use crate::StorageConfig;
6363
static GLOBAL_HICKORY_RESOLVER: LazyLock<Arc<HickoryResolver>> =
6464
LazyLock::new(|| Arc::new(HickoryResolver::default()));
6565

66+
static GLOBAL_HTTP_CLIENT: LazyLock<HttpClient> = LazyLock::new(|| {
67+
new_storage_http_client().unwrap_or_else(|err| {
68+
panic!("http client must be created successfully, but failed for {err}")
69+
})
70+
});
71+
6672
/// init_operator will init an opendal operator based on storage config.
6773
pub fn init_operator(cfg: &StorageParams) -> Result<Operator> {
6874
let op = match &cfg {
@@ -162,7 +168,7 @@ pub fn init_azblob_operator(cfg: &StorageAzblobConfig) -> Result<impl Builder> {
162168
// Credential
163169
.account_name(&cfg.account_name)
164170
.account_key(&cfg.account_key)
165-
.http_client(new_storage_http_client()?);
171+
.http_client(GLOBAL_HTTP_CLIENT.clone());
166172

167173
Ok(builder)
168174
}
@@ -187,7 +193,7 @@ fn init_gcs_operator(cfg: &StorageGcsConfig) -> Result<impl Builder> {
187193
.bucket(&cfg.bucket)
188194
.root(&cfg.root)
189195
.credential(&cfg.credential)
190-
.http_client(new_storage_http_client()?);
196+
.http_client(GLOBAL_HTTP_CLIENT.clone());
191197

192198
Ok(builder)
193199
}
@@ -284,7 +290,7 @@ fn init_s3_operator(cfg: &StorageS3Config) -> Result<impl Builder> {
284290
builder = builder.enable_virtual_host_style();
285291
}
286292

287-
builder = builder.http_client(new_storage_http_client()?);
293+
builder = builder.http_client(GLOBAL_HTTP_CLIENT.clone());
288294

289295
Ok(builder)
290296
}
@@ -301,7 +307,7 @@ fn init_obs_operator(cfg: &StorageObsConfig) -> Result<impl Builder> {
301307
// Credential
302308
.access_key_id(&cfg.access_key_id)
303309
.secret_access_key(&cfg.secret_access_key)
304-
.http_client(new_storage_http_client()?);
310+
.http_client(GLOBAL_HTTP_CLIENT.clone());
305311

306312
Ok(builder)
307313
}
@@ -317,7 +323,7 @@ fn init_oss_operator(cfg: &StorageOssConfig) -> Result<impl Builder> {
317323
.root(&cfg.root)
318324
.server_side_encryption(&cfg.server_side_encryption)
319325
.server_side_encryption_key_id(&cfg.server_side_encryption_key_id)
320-
.http_client(new_storage_http_client()?);
326+
.http_client(GLOBAL_HTTP_CLIENT.clone());
321327

322328
Ok(builder)
323329
}
@@ -350,7 +356,7 @@ fn init_cos_operator(cfg: &StorageCosConfig) -> Result<impl Builder> {
350356
.secret_key(&cfg.secret_key)
351357
.bucket(&cfg.bucket)
352358
.root(&cfg.root)
353-
.http_client(new_storage_http_client()?);
359+
.http_client(GLOBAL_HTTP_CLIENT.clone());
354360

355361
Ok(builder)
356362
}

0 commit comments

Comments
 (0)