瀏覽代碼

增加更好的内存分配器: jemalloc

mikasa 4 周之前
父節點
當前提交
174b8e5709
共有 3 個文件被更改,包括 30 次插入0 次删除
  1. 21 0
      Cargo.lock
  2. 3 0
      Cargo.toml
  3. 6 0
      src/main.rs

+ 21 - 0
Cargo.lock

@@ -620,6 +620,7 @@ dependencies = [
  "serde_yml",
  "socketcan",
  "thiserror 2.0.12",
+ "tikv-jemallocator",
  "tklog",
  "tokio",
  "tokio-cron-scheduler",
@@ -1336,6 +1337,26 @@ dependencies = [
  "syn 2.0.100",
 ]
 
+[[package]]
+name = "tikv-jemalloc-sys"
+version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d"
+dependencies = [
+ "cc",
+ "libc",
+]
+
+[[package]]
+name = "tikv-jemallocator"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4cec5ff18518d81584f477e9bfdf957f5bb0979b0bac3af4ca30b5b3ae2d2865"
+dependencies = [
+ "libc",
+ "tikv-jemalloc-sys",
+]
+
 [[package]]
 name = "tklog"
 version = "0.2.9"

+ 3 - 0
Cargo.toml

@@ -44,5 +44,8 @@ mosquitto-rs = "0.11.2"
 openssl = { version = "0.10.71", features = ["vendored"] }
 # 多核并行处理
 rayon = "1.10.0"
+# 更好的内存分配器
+[target.'cfg(not(target_env = "msvc"))'.dependencies]
+tikv-jemallocator = "0.6.0"
 
 

+ 6 - 0
src/main.rs

@@ -1,5 +1,11 @@
 use inpower_iot_mgc_rs::cmd::cmd::cmd;
 
+#[cfg(not(target_env = "msvc"))]
+use tikv_jemallocator::Jemalloc;
+#[cfg(not(target_env = "msvc"))]
+#[global_allocator]
+static GLOBAL: Jemalloc = Jemalloc;
+
 #[tokio::main]
 async fn main() {
     cmd().await;