Skip to content

Commit

Permalink
Switch to jemalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
mwylde committed Aug 11, 2024
1 parent 964c40c commit f2b607b
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 19 deletions.
146 changes: 127 additions & 19 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/arroyo-server-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition = "2021"
arroyo-types = { path = "../arroyo-types" }
arroyo-rpc = { path = "../arroyo-rpc" }

# tikv-jemallocator = { version = "0.6.0", features = ["profiling", "unprefixed_malloc_on_supported_platforms"] }
jemalloc_pprof = "0.4.2"

# logging
tracing = "0.1"
tracing-logfmt = "0.2.0"
Expand Down
21 changes: 21 additions & 0 deletions crates/arroyo-server-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::Arc;
use std::task::{Context, Poll};
use axum::response::IntoResponse;
use tonic::body::BoxBody;
use tonic::transport::Server;
use tower::layer::util::Stack;
Expand Down Expand Up @@ -232,6 +233,25 @@ async fn details<'a>(State(state): State<Arc<AdminState>>) -> String {
.unwrap()
}


pub async fn handle_get_heap() -> Result<impl IntoResponse, (StatusCode, String)> {
let mut prof_ctl = jemalloc_pprof::PROF_CTL.as_ref().unwrap().lock().await;
require_profiling_activated(&prof_ctl)?;
let pprof = prof_ctl
.dump_pprof()
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?;
Ok(pprof)
}

/// Checks whether jemalloc profiling is activated an returns an error response if not.
fn require_profiling_activated(prof_ctl: &jemalloc_pprof::JemallocProfCtl) -> Result<(), (StatusCode, String)> {
if prof_ctl.activated() {
Ok(())
} else {
Err((axum::http::StatusCode::FORBIDDEN, "heap profiling not activated".into()))
}
}

pub async fn start_admin_server(service: &str) -> anyhow::Result<()> {
let addr = config().admin.bind_address;
let port = config().admin.http_port;
Expand All @@ -248,6 +268,7 @@ pub async fn start_admin_server(service: &str) -> anyhow::Result<()> {
.route("/metrics.pb", get(metrics_proto))
.route("/details", get(details))
.route("/config", get(config_route))
.route("/debug/pprof/heap", get(handle_get_heap))
.with_state(state);

let addr = SocketAddr::new(addr, port);
Expand Down
Loading

0 comments on commit f2b607b

Please sign in to comment.