Skip to content

Commit 0aee047

Browse files
committed
feature gate
1 parent bba593b commit 0aee047

File tree

9 files changed

+89
-86
lines changed

9 files changed

+89
-86
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rustls = [
2929
]
3030
vsock = ["dep:tokio-vsock"]
3131
http3 = ["dep:h3", "dep:h3-quinn", "dep:quinn-proto", "dep:quinn", "dep:http"]
32+
small_instant = ["dep:static_init"]
3233

3334
[dependencies]
3435
anyhow = "1.0.86"
@@ -83,7 +84,7 @@ tokio-vsock = { version = "0.7.2", optional = true }
8384
rusqlite = { version = "0.37.0", features = ["bundled"] }
8485
num_cpus = "1.16.0"
8586
tokio-util = "0.7.13"
86-
static_init = "1.0.4"
87+
static_init = { version = "1.0.4", optional = true }
8788

8889
[target.'cfg(not(target_env = "msvc"))'.dependencies]
8990
tikv-jemallocator = "0.6"

src/client.rs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::{
2323
ConnectToEntry,
2424
pcg64si::Pcg64Si,
2525
request_generator::{RequestGenerationError, RequestGenerator},
26-
small_instant,
2726
url_generator::UrlGeneratorError,
2827
};
2928

@@ -52,16 +51,16 @@ pub struct ConnectionTime {
5251
pub struct RequestResult {
5352
pub rng: Pcg64Si,
5453
// When the query should started
55-
pub start_latency_correction: Option<crate::small_instant::SmallInstant>,
54+
pub start_latency_correction: Option<crate::Instant>,
5655
/// When the query started
57-
pub start: crate::small_instant::SmallInstant,
56+
pub start: crate::Instant,
5857
/// DNS + dialup
5958
/// None when reuse connection
6059
pub connection_time: Option<ConnectionTime>,
6160
/// First body byte received
62-
pub first_byte: Option<crate::small_instant::SmallInstant>,
61+
pub first_byte: Option<crate::Instant>,
6362
/// When the query ends
64-
pub end: crate::small_instant::SmallInstant,
63+
pub end: crate::Instant,
6564
/// HTTP status
6665
pub status: http::StatusCode,
6766
/// Length of body
@@ -497,13 +496,13 @@ impl Client {
497496
url: &Url,
498497
rng: &mut R,
499498
http_version: http::Version,
500-
) -> Result<(crate::small_instant::SmallInstant, Stream), ClientError> {
499+
) -> Result<(crate::Instant, Stream), ClientError> {
501500
let timeout_duration = self.connect_timeout;
502501

503502
#[cfg(feature = "http3")]
504503
if http_version == http::Version::HTTP_3 {
505504
let addr = self.dns.lookup(url, rng).await?;
506-
let dns_lookup = crate::small_instant::SmallInstant::now();
505+
let dns_lookup = crate::Instant::now();
507506
let stream = tokio::time::timeout(timeout_duration, self.quic_client(addr, url)).await;
508507
return match stream {
509508
Ok(Ok(stream)) => Ok((dns_lookup, stream)),
@@ -513,7 +512,7 @@ impl Client {
513512
}
514513
if url.scheme() == "https" {
515514
let addr = self.dns.lookup(url, rng).await?;
516-
let dns_lookup = crate::small_instant::SmallInstant::now();
515+
let dns_lookup = crate::Instant::now();
517516
// If we do not put a timeout here then the connections attempts will
518517
// linger long past the configured timeout
519518
let stream =
@@ -527,7 +526,7 @@ impl Client {
527526
}
528527
#[cfg(unix)]
529528
if let Some(socket_path) = &self.unix_socket {
530-
let dns_lookup = crate::small_instant::SmallInstant::now();
529+
let dns_lookup = crate::Instant::now();
531530
let stream = tokio::time::timeout(
532531
timeout_duration,
533532
tokio::net::UnixStream::connect(socket_path),
@@ -541,7 +540,7 @@ impl Client {
541540
}
542541
#[cfg(feature = "vsock")]
543542
if let Some(addr) = self.vsock_addr {
544-
let dns_lookup = crate::small_instant::SmallInstant::now();
543+
let dns_lookup = crate::Instant::now();
545544
let stream =
546545
tokio::time::timeout(timeout_duration, tokio_vsock::VsockStream::connect(addr))
547546
.await;
@@ -553,7 +552,7 @@ impl Client {
553552
}
554553
// HTTP
555554
let addr = self.dns.lookup(url, rng).await?;
556-
let dns_lookup = crate::small_instant::SmallInstant::now();
555+
let dns_lookup = crate::Instant::now();
557556
let stream =
558557
tokio::time::timeout(timeout_duration, tokio::net::TcpStream::connect(addr)).await;
559558
match stream {
@@ -624,7 +623,7 @@ impl Client {
624623
&self,
625624
url: &Url,
626625
rng: &mut R,
627-
) -> Result<(crate::small_instant::SmallInstant, SendRequestHttp1), ClientError> {
626+
) -> Result<(crate::Instant, SendRequestHttp1), ClientError> {
628627
if let Some(proxy_url) = &self.proxy_url {
629628
let http_proxy_version = if self.is_proxy_http2() {
630629
http::Version::HTTP_2
@@ -687,16 +686,16 @@ impl Client {
687686
) -> Result<RequestResult, ClientError> {
688687
let do_req = async {
689688
let (request, rng) = self.generate_request(&mut client_state.rng)?;
690-
let mut start = crate::small_instant::SmallInstant::now();
691-
let mut first_byte: Option<crate::small_instant::SmallInstant> = None;
689+
let mut start = crate::Instant::now();
690+
let mut first_byte: Option<crate::Instant> = None;
692691
let mut connection_time: Option<ConnectionTime> = None;
693692

694693
let mut send_request = if let Some(send_request) = client_state.send_request.take() {
695694
send_request
696695
} else {
697696
let (dns_lookup, send_request) =
698697
self.client_http1(&self.url, &mut client_state.rng).await?;
699-
let dialup = crate::small_instant::SmallInstant::now();
698+
let dialup = crate::Instant::now();
700699

701700
connection_time = Some(ConnectionTime {
702701
dns_lookup: dns_lookup - start,
@@ -707,11 +706,11 @@ impl Client {
707706
while send_request.ready().await.is_err() {
708707
// This gets hit when the connection for HTTP/1.1 faults
709708
// This re-connects
710-
start = crate::small_instant::SmallInstant::now();
709+
start = crate::Instant::now();
711710
let (dns_lookup, send_request_) =
712711
self.client_http1(&self.url, &mut client_state.rng).await?;
713712
send_request = send_request_;
714-
let dialup = small_instant::SmallInstant::now();
713+
let dialup = crate::Instant::now();
715714
connection_time = Some(ConnectionTime {
716715
dns_lookup: dns_lookup - start,
717716
dialup: dialup - start,
@@ -725,7 +724,7 @@ impl Client {
725724
let mut len_bytes = 0;
726725
while let Some(chunk) = stream.frame().await {
727726
if first_byte.is_none() {
728-
first_byte = Some(crate::small_instant::SmallInstant::now())
727+
first_byte = Some(crate::Instant::now())
729728
}
730729
len_bytes += chunk?.data_ref().map(|d| d.len()).unwrap_or_default();
731730
}
@@ -748,7 +747,7 @@ impl Client {
748747
}
749748
}
750749

751-
let end = crate::small_instant::SmallInstant::now();
750+
let end = crate::Instant::now();
752751

753752
let result = RequestResult {
754753
rng,
@@ -793,7 +792,7 @@ impl Client {
793792
url: &Url,
794793
rng: &mut R,
795794
) -> Result<(ConnectionTime, SendRequestHttp2), ClientError> {
796-
let start = small_instant::SmallInstant::now();
795+
let start = crate::Instant::now();
797796
if let Some(proxy_url) = &self.proxy_url {
798797
let http_proxy_version = if self.is_proxy_http2() {
799798
http::Version::HTTP_2
@@ -843,7 +842,7 @@ impl Client {
843842
.handshake(TokioIo::new(stream))
844843
.await?;
845844
tokio::spawn(conn);
846-
let dialup = crate::small_instant::SmallInstant::now();
845+
let dialup = crate::Instant::now();
847846

848847
Ok((
849848
ConnectionTime {
@@ -854,7 +853,7 @@ impl Client {
854853
))
855854
} else {
856855
let send_request = stream.handshake_http2().await?;
857-
let dialup = small_instant::SmallInstant::now();
856+
let dialup = crate::Instant::now();
858857
Ok((
859858
ConnectionTime {
860859
dns_lookup: dns_lookup - start,
@@ -866,7 +865,7 @@ impl Client {
866865
} else {
867866
let (dns_lookup, stream) = self.client(url, rng, self.http_version).await?;
868867
let send_request = stream.handshake_http2().await?;
869-
let dialup = small_instant::SmallInstant::now();
868+
let dialup = crate::Instant::now();
870869
Ok((
871870
ConnectionTime {
872871
dns_lookup: dns_lookup - start,
@@ -883,8 +882,8 @@ impl Client {
883882
) -> Result<RequestResult, ClientError> {
884883
let do_req = async {
885884
let (request, rng) = self.generate_request(&mut client_state.rng)?;
886-
let start = crate::small_instant::SmallInstant::now();
887-
let mut first_byte: Option<crate::small_instant::SmallInstant> = None;
885+
let start = crate::Instant::now();
886+
let mut first_byte: Option<crate::Instant> = None;
888887
let connection_time: Option<ConnectionTime> = None;
889888

890889
match client_state.send_request.send_request(request).await {
@@ -895,12 +894,12 @@ impl Client {
895894
let mut len_bytes = 0;
896895
while let Some(chunk) = stream.frame().await {
897896
if first_byte.is_none() {
898-
first_byte = Some(crate::small_instant::SmallInstant::now())
897+
first_byte = Some(crate::Instant::now())
899898
}
900899
len_bytes += chunk?.data_ref().map(|d| d.len()).unwrap_or_default();
901900
}
902901

903-
let end = crate::small_instant::SmallInstant::now();
902+
let end = crate::Instant::now();
904903

905904
let result = RequestResult {
906905
rng,
@@ -1066,7 +1065,7 @@ async fn work_http2_once(
10661065
client_state: &mut ClientStateHttp2,
10671066
report_tx: &kanal::Sender<Result<RequestResult, ClientError>>,
10681067
connection_time: ConnectionTime,
1069-
start_latency_correction: Option<crate::small_instant::SmallInstant>,
1068+
start_latency_correction: Option<crate::Instant>,
10701069
) -> (bool, bool) {
10711070
let mut res = client.work_http2(client_state).await;
10721071
let is_cancel = is_cancel_error(&res);
@@ -1090,7 +1089,7 @@ pub(crate) fn set_connection_time<E>(
10901089

10911090
pub(crate) fn set_start_latency_correction<E>(
10921091
res: &mut Result<RequestResult, E>,
1093-
start_latency_correction: crate::small_instant::SmallInstant,
1092+
start_latency_correction: crate::Instant,
10941093
) {
10951094
if let Ok(res) = res {
10961095
res.start_latency_correction = Some(start_latency_correction);
@@ -1466,7 +1465,7 @@ pub async fn work_with_qps_latency_correction(
14661465
(start + std::time::Duration::from_secs_f64(i as f64 * 1f64 / qps)).into(),
14671466
)
14681467
.await;
1469-
let now = crate::small_instant::SmallInstant::now();
1468+
let now = crate::Instant::now();
14701469
tx.send(now)?;
14711470
}
14721471
}
@@ -1475,7 +1474,7 @@ pub async fn work_with_qps_latency_correction(
14751474
// Handle via rate till n_tasks out of bound
14761475
while n + rate < n_tasks {
14771476
tokio::time::sleep(duration).await;
1478-
let now = crate::small_instant::SmallInstant::now();
1477+
let now = crate::Instant::now();
14791478
for _ in 0..rate {
14801479
tx.send(now)?;
14811480
}
@@ -1484,7 +1483,7 @@ pub async fn work_with_qps_latency_correction(
14841483
// Handle the remaining tasks
14851484
if n_tasks > n {
14861485
tokio::time::sleep(duration).await;
1487-
let now = crate::small_instant::SmallInstant::now();
1486+
let now = crate::Instant::now();
14881487
for _ in 0..n_tasks - n {
14891488
tx.send(now)?;
14901489
}
@@ -1611,7 +1610,7 @@ pub async fn work_with_qps_latency_correction(
16111610
pub async fn work_until(
16121611
client: Arc<Client>,
16131612
report_tx: kanal::Sender<Result<RequestResult, ClientError>>,
1614-
dead_line: small_instant::SmallInstant,
1613+
dead_line: crate::Instant,
16151614
n_connections: usize,
16161615
n_http_parallel: usize,
16171616
wait_ongoing_requests_after_deadline: bool,
@@ -1777,8 +1776,8 @@ pub async fn work_until_with_qps(
17771776
client: Arc<Client>,
17781777
report_tx: kanal::Sender<Result<RequestResult, ClientError>>,
17791778
query_limit: QueryLimit,
1780-
start: small_instant::SmallInstant,
1781-
dead_line: small_instant::SmallInstant,
1779+
start: crate::Instant,
1780+
dead_line: crate::Instant,
17821781
n_connections: usize,
17831782
n_http2_parallel: usize,
17841783
wait_ongoing_requests_after_deadline: bool,
@@ -1804,7 +1803,7 @@ pub async fn work_until_with_qps(
18041803
let (tx, rx) = kanal::unbounded::<()>();
18051804
tokio::spawn(async move {
18061805
for i in 0.. {
1807-
if small_instant::SmallInstant::now() > dead_line {
1806+
if crate::Instant::now() > dead_line {
18081807
break;
18091808
}
18101809
tokio::time::sleep_until(
@@ -1825,7 +1824,7 @@ pub async fn work_until_with_qps(
18251824
tokio::spawn(async move {
18261825
// Handle via rate till deadline is reached
18271826
for _ in 0.. {
1828-
if small_instant::SmallInstant::now() > dead_line {
1827+
if crate::Instant::now() > dead_line {
18291828
break;
18301829
}
18311830

@@ -1990,8 +1989,8 @@ pub async fn work_until_with_qps_latency_correction(
19901989
client: Arc<Client>,
19911990
report_tx: kanal::Sender<Result<RequestResult, ClientError>>,
19921991
query_limit: QueryLimit,
1993-
start: small_instant::SmallInstant,
1994-
dead_line: small_instant::SmallInstant,
1992+
start: crate::Instant,
1993+
dead_line: crate::Instant,
19951994
n_connections: usize,
19961995
n_http2_parallel: usize,
19971996
wait_ongoing_requests_after_deadline: bool,
@@ -2024,7 +2023,7 @@ pub async fn work_until_with_qps_latency_correction(
20242023
.into(),
20252024
)
20262025
.await;
2027-
let now = small_instant::SmallInstant::now();
2026+
let now = crate::Instant::now();
20282027
if now > dead_line {
20292028
break;
20302029
}
@@ -2038,7 +2037,7 @@ pub async fn work_until_with_qps_latency_correction(
20382037
// Handle via rate till deadline is reached
20392038
loop {
20402039
tokio::time::sleep(duration).await;
2041-
let now = small_instant::SmallInstant::now();
2040+
let now = crate::Instant::now();
20422041
if now > dead_line {
20432042
break;
20442043
}
@@ -2212,7 +2211,6 @@ pub mod fast {
22122211
},
22132212
pcg64si::Pcg64Si,
22142213
result_data::ResultData,
2215-
small_instant,
22162214
};
22172215

22182216
use super::Client;
@@ -2444,7 +2442,7 @@ pub mod fast {
24442442
pub async fn work_until(
24452443
client: Arc<Client>,
24462444
report_tx: kanal::Sender<ResultData>,
2447-
dead_line: small_instant::SmallInstant,
2445+
dead_line: crate::Instant,
24482446
n_connections: usize,
24492447
n_http_parallel: usize,
24502448
wait_ongoing_requests_after_deadline: bool,

0 commit comments

Comments
 (0)