Skip to content

Commit 7e754c5

Browse files
authored
feat: Add connection pooling in openstack_sdk (#1459)
- add support for connection pooling and timeout - enable deflate, gzip and http2 features of reqwest
1 parent a1de395 commit 7e754c5

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

Cargo.lock

Lines changed: 44 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openstack_sdk/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ json-patch = { workspace = true }
6565
lazy_static = { workspace = true }
6666
open.workspace = true
6767
regex = { workspace = true }
68-
reqwest = { workspace = true }
68+
reqwest = { workspace = true, features = ["gzip", "deflate", "http2",
69+
"system-proxy"] }
6970
secrecy = { version = "0.10", features = ["serde"] }
7071
serde = { workspace = true }
7172
serde_json = {workspace = true}

openstack_sdk/src/openstack_async.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use http::{header, HeaderMap, HeaderValue, Response as HttpResponse, StatusCode}
2323
use reqwest::{Body, Certificate, Client as AsyncClient, Request, Response};
2424
use std::convert::TryInto;
2525
use std::fmt::{self, Debug};
26-
use std::time::SystemTime;
26+
use std::time::{Duration, SystemTime};
2727
use std::{fs::File, io::Read};
2828
use tokio_util::codec;
2929
use tokio_util::compat::FuturesAsyncReadCompatExt;
@@ -193,6 +193,19 @@ impl AsyncOpenStack {
193193
);
194194
client_builder = client_builder.danger_accept_invalid_certs(true);
195195
}
196+
client_builder = client_builder.pool_max_idle_per_host(10);
197+
client_builder = client_builder.pool_idle_timeout(Duration::from_secs(30));
198+
client_builder = client_builder.timeout(Duration::from_secs(
199+
config
200+
.options
201+
.get("api_timeout")
202+
.and_then(|val| val.clone().into_uint().ok())
203+
.unwrap_or(30),
204+
));
205+
client_builder = client_builder.connect_timeout(Duration::from_secs(5));
206+
client_builder = client_builder.tcp_keepalive(Duration::from_secs(60));
207+
client_builder = client_builder.gzip(true);
208+
client_builder = client_builder.deflate(true);
196209

197210
let mut session = AsyncOpenStack {
198211
client: client_builder.build()?,

0 commit comments

Comments
 (0)