From 7afb693930c1fa29fef04dac43ff620121ecabc5 Mon Sep 17 00:00:00 2001 From: "Mr.Panda" Date: Sun, 31 Dec 2023 23:47:19 +0800 Subject: [PATCH] feat: turn balance system allocator; --- Cargo.lock | 2 ++ turn-balance/server/Cargo.toml | 9 +++++++++ turn-balance/server/src/main.rs | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a638d84..fc4170b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2020,7 +2020,9 @@ dependencies = [ "anyhow", "bytes", "clap", + "jemallocator", "log", + "mimalloc", "num_cpus", "prost", "prost-build", diff --git a/turn-balance/server/Cargo.toml b/turn-balance/server/Cargo.toml index 6541684..c267ed6 100644 --- a/turn-balance/server/Cargo.toml +++ b/turn-balance/server/Cargo.toml @@ -18,3 +18,12 @@ num_cpus = "1.15" [build-dependencies] prost-build = "0.12" + +[target.'cfg(not(target_os = "windows"))'.dependencies] +jemallocator = "0.5.4" + +[target.'cfg(target_os = "windows")'.dependencies] +mimalloc = "0.1.37" + +[features] +system_allocator = [] diff --git a/turn-balance/server/src/main.rs b/turn-balance/server/src/main.rs index 1f6c5c6..37eb3ee 100644 --- a/turn-balance/server/src/main.rs +++ b/turn-balance/server/src/main.rs @@ -1,3 +1,11 @@ +#[global_allocator] +#[cfg(all(target_os = "windows", not(feature = "system_allocator")))] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + +#[global_allocator] +#[cfg(all(not(target_os = "windows"), not(feature = "system_allocator")))] +static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; + mod cluster; mod config;