-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pageserver: add
page_trace
API for debugging (#10293)
## Problem When a pageserver is receiving high rates of requests, we don't have a good way to efficiently discover what the client's access pattern is. Closes: #10275 ## Summary of changes - Add `/v1/tenant/x/timeline/y/page_trace?size_limit_bytes=...&time_limit_secs=...` API, which returns a binary buffer. - Add `pagectl page-trace` tool to decode and analyze the output. --------- Co-authored-by: Erik Grinaker <erik@neon.tech>
- Loading branch information
1 parent
efaec6c
commit fb0e2ac
Showing
10 changed files
with
199 additions
and
3 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
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
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,73 @@ | ||
use std::collections::HashMap; | ||
use std::io::BufReader; | ||
|
||
use camino::Utf8PathBuf; | ||
use clap::Parser; | ||
use itertools::Itertools as _; | ||
use pageserver_api::key::{CompactKey, Key}; | ||
use pageserver_api::models::PageTraceEvent; | ||
use pageserver_api::reltag::RelTag; | ||
|
||
/// Parses a page trace (as emitted by the `page_trace` timeline API), and outputs stats. | ||
#[derive(Parser)] | ||
pub(crate) struct PageTraceCmd { | ||
/// Trace input file. | ||
path: Utf8PathBuf, | ||
} | ||
|
||
pub(crate) fn main(cmd: &PageTraceCmd) -> anyhow::Result<()> { | ||
let mut file = BufReader::new(std::fs::OpenOptions::new().read(true).open(&cmd.path)?); | ||
let mut events: Vec<PageTraceEvent> = Vec::new(); | ||
loop { | ||
match bincode::deserialize_from(&mut file) { | ||
Ok(event) => events.push(event), | ||
Err(err) => { | ||
if let bincode::ErrorKind::Io(ref err) = *err { | ||
if err.kind() == std::io::ErrorKind::UnexpectedEof { | ||
break; | ||
} | ||
} | ||
return Err(err.into()); | ||
} | ||
} | ||
} | ||
|
||
let mut reads_by_relation: HashMap<RelTag, i64> = HashMap::new(); | ||
let mut reads_by_key: HashMap<CompactKey, i64> = HashMap::new(); | ||
|
||
for event in events { | ||
let key = Key::from_compact(event.key); | ||
let reltag = RelTag { | ||
spcnode: key.field2, | ||
dbnode: key.field3, | ||
relnode: key.field4, | ||
forknum: key.field5, | ||
}; | ||
|
||
*reads_by_relation.entry(reltag).or_default() += 1; | ||
*reads_by_key.entry(event.key).or_default() += 1; | ||
} | ||
|
||
let multi_read_keys = reads_by_key | ||
.into_iter() | ||
.filter(|(_, count)| *count > 1) | ||
.sorted_by_key(|(key, count)| (-*count, *key)) | ||
.collect_vec(); | ||
|
||
println!("Multi-read keys: {}", multi_read_keys.len()); | ||
for (key, count) in multi_read_keys { | ||
println!(" {key}: {count}"); | ||
} | ||
|
||
let reads_by_relation = reads_by_relation | ||
.into_iter() | ||
.sorted_by_key(|(rel, count)| (-*count, *rel)) | ||
.collect_vec(); | ||
|
||
println!("Reads by relation:"); | ||
for (reltag, count) in reads_by_relation { | ||
println!(" {reltag}: {count}"); | ||
} | ||
|
||
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
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
fb0e2ac
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.
7315 tests run: 6938 passed, 1 failed, 376 skipped (full report)
Failures on Postgres 16
test_physical_replication_config_mismatch_max_locks_per_transaction
: release-arm64Flaky tests (5)
Postgres 17
test_nbtree_pagesplit_cycleid
: release-arm64test_storage_controller_node_deletion[False]
: debug-x86-64Postgres 15
test_physical_replication_config_mismatch_max_locks_per_transaction
: release-x86-64Postgres 14
test_storage_controller_node_deletion[False]
: release-arm64test_scrubber_physical_gc_ancestors[None]
: release-x86-64Test coverage report is not available
fb0e2ac at 2025-01-15T20:02:57.639Z :recycle: