Skip to content

Commit

Permalink
backend: use mimalloc and set nodelay to increase performance (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia authored Dec 3, 2024
1 parent b7f47f4 commit 05a7927
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
20 changes: 20 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 nghe-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ indexmap = { version = "2.6.0" }
libaes = { version = "0.7.0" }
lofty = { version = "0.21.1" }
loole = { version = "0.4.0" }
mimalloc = { version = "0.1.43" }
o2o = { version = "0.5.1-beta1", default-features = false, features = ["syn2"] }
rsmpeg = { version = "0.15.1", default-features = false, features = [
"ffmpeg7",
Expand Down
4 changes: 4 additions & 0 deletions nghe-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ use axum::body::Body;
use axum::http::Request;
use axum::Router;
use error::Error;
use mimalloc::MiMalloc;
use tower_http::compression::CompressionLayer;
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

pub async fn build(config: config::Config) -> Router {
let filesystem =
filesystem::Filesystem::new(&config.filesystem.tls, &config.filesystem.s3).await;
Expand Down
2 changes: 1 addition & 1 deletion nghe-backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ async fn main() {
migration::run(&config.database.url).await;

let listener = tokio::net::TcpListener::bind(config.server.to_socket_addr()).await.unwrap();
axum::serve(listener, build(config).await).await.unwrap();
axum::serve(listener, build(config).await).tcp_nodelay(true).await.unwrap();
}

0 comments on commit 05a7927

Please sign in to comment.