Skip to content

Commit 4aad275

Browse files
committed
Disable Jemalloc on Windows
1 parent 4ec0a52 commit 4aad275

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ serde_json = { optional = true, version = "1.0.128", features = ["preser
6060
smart-default = { optional = true, version = "0.7.1" }
6161
tera = { optional = true, version = "1.20.0" }
6262
thiserror = { version = "1.0.63" }
63-
tikv-jemalloc-ctl = { optional = true, version = "0.6.0", features = ["stats"] }
6463
tokio = { version = "1.40.0", features = ["fs", "io-std", "io-util", "macros", "rt-multi-thread"] }
6564
tokio-util = { optional = true, version = "0.7.12", features = ["io", "io-util"] }
6665
tower-http = { version = "0.5.2", features = ["catch-panic", "trace"] }
@@ -75,12 +74,17 @@ utoipa-redoc = { optional = true, version = "4.0.0", features = ["axum"] }
7574
utoipa-swagger-ui = { optional = true, version = "7.1.0", features = ["axum"] }
7675
velcro = { optional = true, version = "0.5.4" }
7776

77+
[target.'cfg(not(windows))'.dependencies]
78+
tikv-jemalloc-ctl = { optional = true, version = "0.6.0", features = ["stats"] }
79+
7880
[dev-dependencies]
7981
assert-json-diff = "2.0.2"
8082
parking_lot = "0.12.3"
8183
rubedo = "0.6.2"
8284
serde_json = { version = "1.0.128", features = ["preserve_order"] }
8385
smart-default = "0.7.1"
86+
87+
[target.'cfg(not(windows))'.dev-dependencies]
8488
tikv-jemallocator = "0.6.0"
8589

8690
#================================[ EXAMPLES ]=================================

examples/api/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ use terracotta::{
5757
},
5858
stats::worker::start as start_stats_processor,
5959
};
60-
use tikv_jemallocator::Jemalloc;
6160
use tracing::info;
6261
use utoipa::OpenApi;
6362

63+
#[cfg(not(windows))]
64+
use tikv_jemallocator::Jemalloc;
65+
6466

6567

6668
// Constants
6769

6870
/// The global allocator. This is changed to [`Jemalloc`] in order to obtain
6971
/// memory usage statistics.
72+
#[cfg(not(windows))]
7073
#[global_allocator]
7174
static GLOBAL: Jemalloc = Jemalloc;
7275

examples/full/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ use terracotta::{
4848
},
4949
stats::worker::start as start_stats_processor,
5050
};
51-
use tikv_jemallocator::Jemalloc;
5251
use tracing::info;
5352
use utoipa::OpenApi;
5453

54+
#[cfg(not(windows))]
55+
use tikv_jemallocator::Jemalloc;
56+
5557

5658

5759
// Constants
5860

5961
/// The global allocator. This is changed to [`Jemalloc`] in order to obtain
6062
/// memory usage statistics.
63+
#[cfg(not(windows))]
6164
#[global_allocator]
6265
static GLOBAL: Jemalloc = Jemalloc;
6366

examples/minimal/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ use terracotta::app::{
5151
init::{load_config, setup_logging},
5252
state::StateProvider,
5353
};
54-
use tikv_jemallocator::Jemalloc;
5554
use tracing::info;
5655

56+
#[cfg(not(windows))]
57+
use tikv_jemallocator::Jemalloc;
58+
5759

5860

5961
// Constants
6062

6163
/// The global allocator. This is changed to [`Jemalloc`] in order to obtain
6264
/// memory usage statistics.
65+
#[cfg(not(windows))]
6366
#[global_allocator]
6467
static GLOBAL: Jemalloc = Jemalloc;
6568

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub mod stats;
5757
mod examples {
5858
use parking_lot as _;
5959
use smart_default as _;
60+
#[cfg(not(windows))]
6061
use tikv_jemallocator as _;
6162
}
6263

src/stats/middleware.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ use chrono::{NaiveDateTime, Utc};
2323
use core::sync::atomic::Ordering;
2424
use smart_default::SmartDefault;
2525
use std::sync::Arc;
26-
use tikv_jemalloc_ctl::stats::allocated as Malloc;
27-
use tracing::{error, warn};
26+
use tracing::error;
27+
28+
#[cfg(not(windows))]
29+
use ::{
30+
tikv_jemalloc_ctl::stats::allocated as Malloc,
31+
tracing::warn,
32+
};
2833

2934

3035

@@ -124,10 +129,15 @@ pub async fn stats_layer<SP: StateProvider>(
124129
,
125130
status_code: response.status(),
126131
connections: stats_state.data.connections.load(Ordering::Relaxed) as u64,
127-
memory: Malloc::read()
128-
.inspect_err(|err| warn!("Could not read memory usage: {err}"))
129-
.unwrap_or_default() as u64
130-
,
132+
memory: {
133+
#[cfg(not(windows))]
134+
{ Malloc::read()
135+
.inspect_err(|err| warn!("Could not read memory usage: {err}"))
136+
.unwrap_or_default() as u64
137+
}
138+
#[cfg(windows)]
139+
{ 0_u64 }
140+
},
131141
}).await.inspect_err(|err| error!("Failed to send response time: {err}")));
132142
}
133143

0 commit comments

Comments
 (0)