Skip to content

Commit 9085261

Browse files
committed
feat(mimalloc): add mimalloc as global allocator
This is necessary to reduce memory-fragmentation and overalll ram usage in long running deployments
1 parent 071487d commit 9085261

6 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Optional `mimalloc` feature that uses mimalloc as the global allocator. Enabled by default in the Docker images to reduce memory growth in long-running deployments (#68)
13+
1214
### Fixed
1315

1416
### Changed

‎Cargo.lock‎

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ readme = "README.md"
1717
[features]
1818
default = []
1919
s3 = ["dep:aws-config", "dep:aws-sdk-s3", "dep:aws-credential-types"]
20+
# Use mimalloc as the global allocator (reduces memory fragmentation in long-running deployments)
21+
mimalloc = ["dep:mimalloc"]
2022

2123
[dependencies]
2224
# DICOM processing
@@ -53,6 +55,7 @@ multer = "3.1.0"
5355
pin-project = "1.1.10"
5456
image = { version = "0.25.8", features = ["png", "jpeg", "gif"] }
5557
http-body-util = "0.1.3"
58+
mimalloc = { version = "0.1", optional = true }
5659

5760
# S3 backend
5861
aws-config = { version = "1.8.14", features = ["behavior-version-latest"], optional = true }

‎Dockerfile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ RUN cargo chef prepare --recipe-path recipe.json
88
FROM chef AS builder
99
COPY --from=planner /app/recipe.json recipe.json
1010

11-
RUN cargo chef cook --release --recipe-path recipe.json
11+
RUN cargo chef cook --release --features mimalloc --recipe-path recipe.json
1212

1313
COPY . .
14-
RUN cargo build --release --bin dicom-rst
14+
RUN cargo build --release --features mimalloc --bin dicom-rst
1515

1616
FROM gcr.io/distroless/cc-debian12 AS runtime
1717
COPY --from=builder /app/target/release/dicom-rst /

‎Dockerfile-s3‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WORKDIR /app
55

66
COPY . .
77

8-
RUN cargo build --release --locked --features s3 --bin dicom-rst
8+
RUN cargo build --release --locked --features s3,mimalloc --bin dicom-rst
99

1010
FROM gcr.io/distroless/cc-debian12 AS runtime
1111
COPY --from=builder /app/target/release/dicom-rst /

‎src/main.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ use tracing_subscriber::layer::SubscriberExt;
3131
use tracing_subscriber::util::SubscriberInitExt;
3232
use tracing_subscriber::EnvFilter;
3333

34+
#[cfg(feature = "mimalloc")]
35+
#[global_allocator]
36+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
37+
3438
/// The implementation class UID for DICOM-RST.
3539
/// The UID is a randomly generated UUID represented as a single integer value under the 2.25 root.
3640
pub const IMPLEMENTATION_CLASS_UID: &str = "2.25.94508551356620097453554517680708411706";

0 commit comments

Comments
 (0)