diff --git a/Cargo.lock b/Cargo.lock index 57115be..1ed3e3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,6 +141,7 @@ dependencies = [ "jsonwebtoken", "log", "log4rs", + "mimalloc", "moka", "notify", "pingora", @@ -161,8 +162,6 @@ dependencies = [ "sha2 0.11.0", "signal-hook", "subtle", - "tikv-jemalloc-ctl", - "tikv-jemallocator", "tokio", "tonic", "tower-http", @@ -1917,6 +1916,15 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" +[[package]] +name = "libmimalloc-sys" +version = "0.1.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9" +dependencies = [ + "cc", +] + [[package]] name = "libyml" version = "0.0.5" @@ -2043,6 +2051,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mimalloc" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" @@ -2428,12 +2445,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - [[package]] name = "pem" version = "3.0.6" @@ -3880,37 +3891,6 @@ dependencies = [ "trackable", ] -[[package]] -name = "tikv-jemalloc-ctl" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a184c43b8ab2f41df2733b55556e3f5f632f4aeaa205b1bb018f574b7f5f142" -dependencies = [ - "libc", - "paste", - "tikv-jemalloc-sys", -] - -[[package]] -name = "tikv-jemalloc-sys" -version = "0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a2825c78386b4ae0314074867860ba9577875de945f05992c38815cbec327f0" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "tikv-jemallocator" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "249f09e49ab1609436f34c776e84231bead18d6a955f119f939bdc1d847561bd" -dependencies = [ - "libc", - "tikv-jemalloc-sys", -] - [[package]] name = "time" version = "0.3.47" diff --git a/Cargo.toml b/Cargo.toml index 344eafb..2086381 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,8 +46,6 @@ ahash = "0.8.12" instant-acme = "0.8.5" rcgen = "0.14.8" log4rs = "1.4.0" -#mimalloc = { version = "0.1.52", default-features = false } -tikv-jemallocator = "0.7.0" -tikv-jemalloc-ctl = { version = "0.7.0", features = ["stats"] } +mimalloc = { version = "0.1.52", default-features = false } signal-hook = "0.4.4" sd-notify = "0.5.0" diff --git a/src/main.rs b/src/main.rs index 2a35e0e..d3741f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,10 @@ -use tikv_jemallocator::Jemalloc; - mod tls; mod utils; mod web; #[global_allocator] -static ALLOC: Jemalloc = Jemalloc; -// static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; +// static ALLOC: Jemalloc = Jemalloc; +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; // pub static A: CountingAllocator = CountingAllocator; fn main() { diff --git a/src/utils/metrics.rs b/src/utils/metrics.rs index 5378989..7a4e879 100644 --- a/src/utils/metrics.rs +++ b/src/utils/metrics.rs @@ -5,7 +5,6 @@ use prometheus::{register_histogram, register_int_counter, register_int_counter_ use std::sync::Arc; use std::sync::LazyLock; use std::time::Duration; -use tikv_jemalloc_ctl::{epoch, stats}; pub struct MetricTypes { pub method: Method, @@ -66,9 +65,17 @@ pub fn calc_metrics(metric_types: &MetricTypes) { RESPONSE_LATENCY.observe(metric_types.latency.as_secs_f64()); } -pub fn get_memory_usage() -> usize { - epoch::mib().unwrap().advance().unwrap(); // refresh stats - stats::allocated::mib().unwrap().read().unwrap() // bytes allocated +pub(crate) fn get_memory_usage() -> usize { + std::fs::read_to_string("/proc/self/status") + .ok() + .and_then(|s| { + s.lines() + .find(|l| l.starts_with("VmRSS:")) + .and_then(|l| l.split_whitespace().nth(1)) + .and_then(|v| v.parse::().ok()) + }) + .unwrap_or(0) + * 1024 } pub fn get_open_files() -> usize {