mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-26 07:39:58 +00:00
safekeeper: use jemalloc (#9780)
## Problem To add Safekeeper heap profiling in #9778, we need to switch to an allocator that supports it. Pageserver and proxy already use jemalloc. Touches #9534. ## Summary of changes Use jemalloc in Safekeeper.
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -5409,6 +5409,7 @@ dependencies = [
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"thiserror",
|
||||
"tikv-jemallocator",
|
||||
"tokio",
|
||||
"tokio-io-timeout",
|
||||
"tokio-postgres",
|
||||
|
||||
@@ -41,6 +41,7 @@ serde_json.workspace = true
|
||||
strum.workspace = true
|
||||
strum_macros.workspace = true
|
||||
thiserror.workspace = true
|
||||
tikv-jemallocator.workspace = true
|
||||
tokio = { workspace = true, features = ["fs"] }
|
||||
tokio-util = { workspace = true }
|
||||
tokio-io-timeout.workspace = true
|
||||
|
||||
@@ -6,6 +6,7 @@ mod benchutils;
|
||||
use std::io::Write as _;
|
||||
|
||||
use benchutils::Env;
|
||||
use bytes::BytesMut;
|
||||
use camino_tempfile::tempfile;
|
||||
use criterion::{criterion_group, criterion_main, BatchSize, Bencher, Criterion};
|
||||
use itertools::Itertools as _;
|
||||
@@ -23,6 +24,9 @@ const KB: usize = 1024;
|
||||
const MB: usize = 1024 * KB;
|
||||
const GB: usize = 1024 * MB;
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||
|
||||
// Register benchmarks with Criterion.
|
||||
criterion_group!(
|
||||
name = benches;
|
||||
@@ -30,7 +34,8 @@ criterion_group!(
|
||||
targets = bench_process_msg,
|
||||
bench_wal_acceptor,
|
||||
bench_wal_acceptor_throughput,
|
||||
bench_file_write
|
||||
bench_file_write,
|
||||
bench_bytes_reserve,
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
||||
@@ -341,3 +346,26 @@ fn bench_file_write(c: &mut Criterion) {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Benchmarks the cost of memory allocations when receiving WAL messages. This emulates the logic
|
||||
/// in FeMessage::parse, which extends the read buffer. It is primarily intended to test jemalloc.
|
||||
fn bench_bytes_reserve(c: &mut Criterion) {
|
||||
let mut g = c.benchmark_group("bytes_reserve");
|
||||
for size in [1, 64, KB, 8 * KB, 128 * KB] {
|
||||
g.throughput(criterion::Throughput::Bytes(size as u64));
|
||||
g.bench_function(format!("size={size}"), |b| run_bench(b, size).unwrap());
|
||||
}
|
||||
|
||||
fn run_bench(b: &mut Bencher, size: usize) -> anyhow::Result<()> {
|
||||
let mut bytes = BytesMut::new();
|
||||
let data = vec![0; size];
|
||||
|
||||
b.iter(|| {
|
||||
bytes.reserve(size);
|
||||
bytes.extend_from_slice(&data);
|
||||
bytes.split_to(size).freeze();
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ use utils::{
|
||||
tcp_listener,
|
||||
};
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||
|
||||
const PID_FILE_NAME: &str = "safekeeper.pid";
|
||||
const ID_FILE_NAME: &str = "safekeeper.id";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user