-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
postgres_ffi: add
WalStreamDecoder::complete_record()
benchmark (#1…
- Loading branch information
1 parent
e226d7a
commit b0e43c2
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## Benchmarks | ||
|
||
To run benchmarks: | ||
|
||
```sh | ||
# All benchmarks. | ||
cargo bench --package postgres_ffi | ||
|
||
# Specific file. | ||
cargo bench --package postgres_ffi --bench waldecoder | ||
|
||
# Specific benchmark. | ||
cargo bench --package postgres_ffi --bench waldecoder complete_record/size=1024 | ||
|
||
# List available benchmarks. | ||
cargo bench --package postgres_ffi --benches -- --list | ||
|
||
# Generate flamegraph profiles using pprof-rs, profiling for 10 seconds. | ||
# Output in target/criterion/*/profile/flamegraph.svg. | ||
cargo bench --package postgres_ffi --bench waldecoder complete_record/size=1024 -- --profile-time 10 | ||
``` | ||
|
||
Additional charts and statistics are available in `target/criterion/report/index.html`. | ||
|
||
Benchmarks are automatically compared against the previous run. To compare against other runs, see | ||
`--baseline` and `--save-baseline`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::ffi::CStr; | ||
|
||
use criterion::{criterion_group, criterion_main, Bencher, Criterion}; | ||
use postgres_ffi::v17::wal_generator::LogicalMessageGenerator; | ||
use postgres_ffi::v17::waldecoder_handler::WalStreamDecoderHandler; | ||
use postgres_ffi::waldecoder::WalStreamDecoder; | ||
use pprof::criterion::{Output, PProfProfiler}; | ||
use utils::lsn::Lsn; | ||
|
||
const KB: usize = 1024; | ||
|
||
// Register benchmarks with Criterion. | ||
criterion_group!( | ||
name = benches; | ||
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); | ||
targets = bench_complete_record, | ||
); | ||
criterion_main!(benches); | ||
|
||
/// Benchmarks WalStreamDecoder::complete_record() for a logical message of varying size. | ||
fn bench_complete_record(c: &mut Criterion) { | ||
let mut g = c.benchmark_group("complete_record"); | ||
for size in [64, KB, 8 * KB, 128 * KB] { | ||
// Kind of weird to change the group throughput per benchmark, but it's the only way | ||
// to vary it per benchmark. It works. | ||
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<()> { | ||
const PREFIX: &CStr = c""; | ||
let value_size = LogicalMessageGenerator::make_value_size(size, PREFIX); | ||
let value = vec![1; value_size]; | ||
|
||
let mut decoder = WalStreamDecoder::new(Lsn(0), 170000); | ||
let msg = LogicalMessageGenerator::new(PREFIX, &value) | ||
.next() | ||
.unwrap() | ||
.encode(Lsn(0)); | ||
assert_eq!(msg.len(), size); | ||
|
||
b.iter(|| { | ||
let msg = msg.clone(); // Bytes::clone() is cheap | ||
decoder.complete_record(msg).unwrap(); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b0e43c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7245 tests run: 6937 passed, 1 failed, 307 skipped (full report)
Failures on Postgres 16
test_storage_controller_many_tenants[github-actions-selfhosted]
: release-x86-64Code coverage* (full report)
functions
:31.3% (8396 of 26786 functions)
lines
:48.0% (66601 of 138639 lines)
* collected from Rust tests only
b0e43c2 at 2024-12-17T12:48:22.723Z :recycle: