mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
perf: use in-memory length for static files metrics (#20987)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -10204,7 +10204,6 @@ dependencies = [
|
||||
"reth-ethereum-engine-primitives",
|
||||
"reth-ethereum-primitives",
|
||||
"reth-execution-types",
|
||||
"reth-fs-util",
|
||||
"reth-metrics",
|
||||
"reth-nippy-jar",
|
||||
"reth-node-types",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! reth's static file database table import and access
|
||||
|
||||
use std::{collections::HashMap, path::Path};
|
||||
use alloy_primitives::map::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
mod cursor;
|
||||
pub use cursor::StaticFileCursor;
|
||||
@@ -44,8 +45,8 @@ pub fn iter_static_files(path: &Path) -> Result<SortedStaticFiles, NippyJarError
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by block end range.
|
||||
for range_list in static_files.values_mut() {
|
||||
// Sort by block end range.
|
||||
range_list.sort_by_key(|(block_range, _)| block_range.end());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
error::Error as StdError,
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
io::{self, Read, Write},
|
||||
ops::Range,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@@ -201,11 +201,11 @@ impl<H: NippyJarHeader> NippyJar<H> {
|
||||
let config_path = path.with_extension(CONFIG_FILE_EXTENSION);
|
||||
let config_file = File::open(&config_path)
|
||||
.inspect_err(|e| {
|
||||
warn!( ?path, %e, "Failed to load static file jar");
|
||||
warn!(?path, %e, "Failed to load static file jar");
|
||||
})
|
||||
.map_err(|err| reth_fs_util::FsPathError::open(err, config_path))?;
|
||||
|
||||
let mut obj = Self::load_from_reader(config_file)?;
|
||||
let mut obj = Self::load_from_reader(io::BufReader::new(config_file))?;
|
||||
obj.path = path.to_path_buf();
|
||||
Ok(obj)
|
||||
}
|
||||
@@ -418,10 +418,15 @@ impl DataReader {
|
||||
&self.data_mmap[range]
|
||||
}
|
||||
|
||||
/// Returns total size of data
|
||||
/// Returns total size of data file.
|
||||
pub fn size(&self) -> usize {
|
||||
self.data_mmap.len()
|
||||
}
|
||||
|
||||
/// Returns total size of offsets file.
|
||||
pub fn offsets_size(&self) -> usize {
|
||||
self.offset_mmap.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -17,7 +17,6 @@ reth-chainspec.workspace = true
|
||||
reth-execution-types.workspace = true
|
||||
reth-ethereum-primitives = { workspace = true, features = ["reth-codec"] }
|
||||
reth-primitives-traits = { workspace = true, features = ["reth-codec", "secp256k1"] }
|
||||
reth-fs-util.workspace = true
|
||||
reth-errors.workspace = true
|
||||
reth-storage-errors.workspace = true
|
||||
reth-storage-api = { workspace = true, features = ["std", "db-api"] }
|
||||
|
||||
@@ -85,6 +85,11 @@ impl<'a, N: NodePrimitives> StaticFileJarProvider<'a, N> {
|
||||
self.metrics = Some(metrics);
|
||||
self
|
||||
}
|
||||
|
||||
/// Returns the total size of the data and offsets files (from the in-memory mmap).
|
||||
pub fn size(&self) -> usize {
|
||||
self.jar.value().size()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NodePrimitives<BlockHeader: Value>> HeaderProvider for StaticFileJarProvider<'_, N> {
|
||||
|
||||
@@ -474,6 +474,9 @@ impl<N: NodePrimitives> StaticFileProviderInner<N> {
|
||||
|
||||
impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
/// Reports metrics for the static files.
|
||||
///
|
||||
/// This uses the in-memory index to get file sizes from mmap handles instead of reading
|
||||
/// filesystem metadata.
|
||||
pub fn report_metrics(&self) -> ProviderResult<()> {
|
||||
let Some(metrics) = &self.metrics else { return Ok(()) };
|
||||
|
||||
@@ -491,29 +494,7 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
|
||||
})?;
|
||||
|
||||
entries += jar_provider.rows();
|
||||
|
||||
let data_path = jar_provider.data_path().to_path_buf();
|
||||
let index_path = jar_provider.index_path();
|
||||
let offsets_path = jar_provider.offsets_path();
|
||||
let config_path = jar_provider.config_path();
|
||||
|
||||
// can release jar early
|
||||
drop(jar_provider);
|
||||
|
||||
let data_size = reth_fs_util::metadata(data_path)
|
||||
.map(|metadata| metadata.len())
|
||||
.unwrap_or_default();
|
||||
let index_size = reth_fs_util::metadata(index_path)
|
||||
.map(|metadata| metadata.len())
|
||||
.unwrap_or_default();
|
||||
let offsets_size = reth_fs_util::metadata(offsets_path)
|
||||
.map(|metadata| metadata.len())
|
||||
.unwrap_or_default();
|
||||
let config_size = reth_fs_util::metadata(config_path)
|
||||
.map(|metadata| metadata.len())
|
||||
.unwrap_or_default();
|
||||
|
||||
size += data_size + index_size + offsets_size + config_size;
|
||||
size += jar_provider.size() as u64;
|
||||
}
|
||||
|
||||
metrics.record_segment(segment, size, headers.len(), entries);
|
||||
|
||||
@@ -44,6 +44,11 @@ impl LoadedJar {
|
||||
const fn segment(&self) -> StaticFileSegment {
|
||||
self.jar.user_header().segment()
|
||||
}
|
||||
|
||||
/// Returns the total size of the data and offsets files (from the in-memory mmap).
|
||||
fn size(&self) -> usize {
|
||||
self.mmap_handle.size() + self.mmap_handle.offsets_size()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for LoadedJar {
|
||||
|
||||
Reference in New Issue
Block a user