From 5b63b0b3989b724ac15bf276886b6245dc43aa9a Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Sat, 27 Jan 2024 18:13:52 -0500 Subject: [PATCH] jemalloc (#861) * jemalloc * featurizeP --------- Co-authored-by: Wyatt Verchere --- Cargo.lock | 28 ++++++++++++++++++++++++++++ Cargo.toml | 5 +++++ Dockerfile | 4 ++-- src/main.rs | 4 ++++ src/search/indexing/mod.rs | 21 +++++++++++++-------- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 469368993..cbdd72c65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1633,6 +1633,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "funty" version = "2.0.0" @@ -2222,6 +2228,27 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "jemalloc-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" +dependencies = [ + "cc", + "fs_extra", + "libc", +] + +[[package]] +name = "jemallocator" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" +dependencies = [ + "jemalloc-sys", + "libc", +] + [[package]] name = "jobserver" version = "0.1.27" @@ -2309,6 +2336,7 @@ dependencies = [ "hyper-tls", "image", "itertools 0.12.0", + "jemallocator", "json-patch", "lazy_static", "lettre", diff --git a/Cargo.toml b/Cargo.toml index 901892252..90da500ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,6 +108,8 @@ lettre = "0.11.3" derive-new = "0.6.0" rust_iso3166 = "0.1.11" +jemallocator = {version = "0.3.2", optional = true} + [dev-dependencies] actix-http = "3.4.0" json-patch = "*" @@ -116,3 +118,6 @@ opt-level = 0 # Minimal optimization, speeds up compilation lto = false # Disables Link Time Optimization incremental = true # Enables incremental compilation codegen-units = 16 # Higher number can improve compile times but reduce runtime performance + +[features] +jemalloc = ["jemallocator"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d972e613e..6a8aab793 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY docker_utils/dummy.rs . # Change temporarely the path of the code RUN sed -i 's|src/main.rs|dummy.rs|' Cargo.toml # Build only deps -RUN cargo build --release +RUN cargo build --release --features jemalloc # Now return the file back to normal RUN sed -i 's|dummy.rs|src/main.rs|' Cargo.toml @@ -17,7 +17,7 @@ RUN sed -i 's|dummy.rs|src/main.rs|' Cargo.toml COPY . . # Build our code ARG SQLX_OFFLINE=true -RUN cargo build --release +RUN cargo build --release --features jemalloc # Final Stage FROM ubuntu:latest diff --git a/src/main.rs b/src/main.rs index e242509f0..bbdf6b7f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,10 @@ use labrinth::{check_env_vars, clickhouse, database, file_hosting, queue}; use log::{error, info}; use std::sync::Arc; +#[cfg(feature = "jemalloc")] +#[global_allocator] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; + #[derive(Clone)] pub struct Pepper { pub pepper: String, diff --git a/src/search/indexing/mod.rs b/src/search/indexing/mod.rs index 05919a1bb..35b7f72ce 100644 --- a/src/search/indexing/mod.rs +++ b/src/search/indexing/mod.rs @@ -115,14 +115,19 @@ pub async fn get_indexes_for_indexing( let client = config.make_client(); let project_name = config.get_index_name("projects", next); let project_filtered_name = config.get_index_name("projects_filtered", next); - let projects_index = create_or_update_index(&client, &project_name, Some(&[ - "words", - "typo", - "proximity", - "attribute", - "exactness", - "sort", - ]),).await?; + let projects_index = create_or_update_index( + &client, + &project_name, + Some(&[ + "words", + "typo", + "proximity", + "attribute", + "exactness", + "sort", + ]), + ) + .await?; let projects_filtered_index = create_or_update_index( &client, &project_filtered_name,