Skip to content

Commit 6538ce6

Browse files
deuszxndr-ds
andauthored
Backport node service memory profiling (#4610)
## Motivation Profile memory consumption on testnet. ## Proposal Backport necessary PRs. ## Test Plan Manual. cc @ndr-ds ## Release Plan - Nothing to do ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist) --------- Co-authored-by: Andre da Silva <[email protected]>
1 parent 928900e commit 6538ce6

File tree

18 files changed

+555
-93
lines changed

18 files changed

+555
-93
lines changed

Cargo.lock

Lines changed: 151 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ indexed_db_futures = "0.4.1"
136136
insta = "1.36.1"
137137
is-terminal = "0.4.12"
138138
itertools = "0.14.0"
139+
jemalloc_pprof = "0.8.1"
139140
js-sys = "0.3.70"
140141
k256 = { version = "0.13.4", default-features = false, features = [
141142
"ecdsa",
@@ -234,6 +235,7 @@ test-log = { version = "0.2.15", default-features = false, features = [
234235
test-strategy = "0.3.1"
235236
thiserror = "1.0.65"
236237
thiserror-context = "0.1.1"
238+
tikv-jemallocator = "0.6.0"
237239
tokio = "1.36.0"
238240
tokio-stream = "0.1.14"
239241
tokio-test = "0.4.3"

docker/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ARG binaries=
2525
ARG copy=${binaries:+_copy}
2626
ARG build_flag=--release
2727
ARG build_folder=release
28-
ARG build_features=scylladb,metrics
28+
ARG build_features=scylladb,metrics,memory-profiling
2929
ARG rustflags="-C force-frame-pointers=yes"
3030

3131
FROM rust:1.74-slim-bookworm AS builder
@@ -39,7 +39,8 @@ ARG rustflags
3939
RUN apt-get update && apt-get install -y \
4040
pkg-config \
4141
protobuf-compiler \
42-
clang
42+
clang \
43+
make
4344

4445
COPY examples examples
4546
COPY linera-base linera-base

linera-faucet/server/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use linera_execution::{
4242
Committee, ExecutionError, Operation,
4343
};
4444
#[cfg(feature = "metrics")]
45-
use linera_metrics::prometheus_server;
45+
use linera_metrics::monitoring_server;
4646
use linera_storage::{Clock as _, Storage};
4747
use serde::{Deserialize, Serialize};
4848
use tokio::sync::{oneshot, Notify};
@@ -652,7 +652,7 @@ where
652652
let index_handler = axum::routing::get(graphiql).post(Self::index_handler);
653653

654654
#[cfg(feature = "metrics")]
655-
prometheus_server::start_metrics(self.metrics_address(), cancellation_token.clone());
655+
monitoring_server::start_metrics(self.metrics_address(), cancellation_token.clone());
656656

657657
let app = Router::new()
658658
.route("/", index_handler)
@@ -692,7 +692,9 @@ where
692692
let batch_processor_task = batch_processor.run(cancellation_token.clone());
693693
let tcp_listener =
694694
tokio::net::TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], port))).await?;
695-
let server = axum::serve(tcp_listener, app).into_future();
695+
let server = axum::serve(tcp_listener, app)
696+
.with_graceful_shutdown(cancellation_token.cancelled_owned())
697+
.into_future();
696698
futures::select! {
697699
result = Box::pin(chain_listener).fuse() => result?,
698700
_ = Box::pin(batch_processor_task).fuse() => {},

linera-metrics/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@ version.workspace = true
1414
[lints]
1515
workspace = true
1616

17+
[features]
18+
memory-profiling = ["jemalloc_pprof"]
19+
1720
[dependencies]
1821
anyhow.workspace = true
1922
axum.workspace = true
23+
jemalloc_pprof = { workspace = true, features = [
24+
"symbolize",
25+
"flamegraph",
26+
], optional = true }
2027
prometheus.workspace = true
28+
thiserror.workspace = true
2129
tokio = { workspace = true, features = ["full"] }
2230
tokio-util.workspace = true
2331
tracing.workspace = true

linera-metrics/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44
//! A library for Linera server metrics.
55
6-
pub mod prometheus_server;
6+
pub mod monitoring_server;
7+
8+
#[cfg(feature = "memory-profiling")]
9+
pub mod memory_profiler;

0 commit comments

Comments
 (0)