Skip to content

Commit

Permalink
Replace system allocator with mimalloc (#3087)
Browse files Browse the repository at this point in the history
# Description
I looked more into the supposed memory leak and noticed that the system
allocator requires unreasonable amounts of memory compared to
[mimalloc](https://www.google.com/search?client=firefox-b-d&q=mimalloc+github)
so I replaced it for all the binaries.

Here we can see the memory footprint of the api pod with `mimalloc`
(green) and the system allocator (yellow). The served traffic is the
same but the system allocator continues to require more and more memory
- probably because it's worse at dealing with memory fragmentation than
`mimalloc`.

<img width="1184" alt="Screenshot 2024-10-26 at 17 10 42"
src="https://github.com/user-attachments/assets/479a464c-a4a9-4a50-8cf8-05e09d2a45a8">
  • Loading branch information
MartinquaXD authored Oct 28, 2024
1 parent 2c92f95 commit c0b1f9e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ clap = { version = "4.5.6", features = ["derive", "env"] }
derivative = "2.2.0"
derive_more = "0.99.17"
ethcontract = { version = "0.25.7", default-features = false, features = ["aws-kms"] }
mimalloc = "0.1.43"
ethcontract-generate = { version = "0.25.7", default-features = false }
ethcontract-mock = { version = "0.25.7", default-features = false }
ethereum-types = "0.14.1"
Expand Down
1 change: 1 addition & 0 deletions crates/alerter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chrono = { workspace = true }
clap = { workspace = true }
humantime = { workspace = true }
observe = { path = "../observe" }
mimalloc = { workspace = true }
model = { path = "../model" }
number = { path = "../number" }
primitive-types = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/alerter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() {
alerter::start(std::env::args()).await;
Expand Down
1 change: 1 addition & 0 deletions crates/autopilot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ humantime = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
maplit = { workspace = true }
mimalloc = { workspace = true }
model = { path = "../model" }
num = { workspace = true }
number = { path = "../number" }
Expand Down
3 changes: 3 additions & 0 deletions crates/autopilot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() {
autopilot::start(std::env::args()).await;
Expand Down
1 change: 1 addition & 0 deletions crates/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ hyper = { workspace = true }
lazy_static = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
itertools = { workspace = true }
mimalloc = { workspace = true }
num = { workspace = true }
number = { path = "../number" }
prometheus = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/driver/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() {
driver::start(std::env::args()).await;
Expand Down
1 change: 1 addition & 0 deletions crates/orderbook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ hex-literal = { workspace = true }
humantime = { workspace = true }
hyper = { workspace = true }
maplit = { workspace = true }
mimalloc = { workspace = true }
model = { path = "../model" }
multibase = "0.9"
num = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/orderbook/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() {
orderbook::start(std::env::args()).await;
Expand Down
1 change: 1 addition & 0 deletions crates/refunder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ futures = {workspace = true}
gas-estimation = { workspace = true }
humantime = { workspace = true }
lazy_static = { workspace = true }
mimalloc = "0.1.43"
model = { path = "../model" }
number = { path = "../number" }
observe = { path = "../observe" }
Expand Down
3 changes: 3 additions & 0 deletions crates/refunder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() {
refunder::start(std::env::args()).await
Expand Down
1 change: 1 addition & 0 deletions crates/solvers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ futures = { workspace = true }
hex = { workspace = true }
hyper = { workspace = true }
itertools = { workspace = true }
mimalloc = { workspace = true }
num = { workspace = true }
prometheus = { workspace = true }
prometheus-metric-storage = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/solvers/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() {
solvers::start(std::env::args()).await;
Expand Down

0 comments on commit c0b1f9e

Please sign in to comment.