mirror of
https://github.com/romanz/electrs.git
synced 2025-02-24 23:08:39 +01:00
Log indexing statistics (blocks, txns, vsize)
This commit is contained in:
parent
49afcc658f
commit
c0a4f7a520
1 changed files with 31 additions and 5 deletions
36
src/index.rs
36
src/index.rs
|
@ -250,6 +250,31 @@ fn read_indexed_headers(store: &ReadStore) -> HeaderList {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Stats {
|
||||||
|
blocks: usize,
|
||||||
|
txns: usize,
|
||||||
|
vsize: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stats {
|
||||||
|
fn new() -> Stats {
|
||||||
|
Stats {
|
||||||
|
blocks: 0,
|
||||||
|
txns: 0,
|
||||||
|
vsize: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, block: &Block) {
|
||||||
|
self.blocks += 1;
|
||||||
|
self.txns += block.txdata.len();
|
||||||
|
for tx in &block.txdata {
|
||||||
|
self.vsize += tx.get_weight() as usize / 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Index {
|
pub struct Index {
|
||||||
// TODO: store also latest snapshot.
|
// TODO: store also latest snapshot.
|
||||||
headers: RwLock<HeaderList>,
|
headers: RwLock<HeaderList>,
|
||||||
|
@ -286,6 +311,7 @@ impl Index {
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
let mut timer = Timer::new();
|
let mut timer = Timer::new();
|
||||||
|
let mut stats = Stats::new();
|
||||||
let mut bar = util::new_progress_bar(new_headers.len());
|
let mut bar = util::new_progress_bar(new_headers.len());
|
||||||
bar.message("Blocks: ");
|
bar.message("Blocks: ");
|
||||||
let mut buf = BufferedWriter::new(store);
|
let mut buf = BufferedWriter::new(store);
|
||||||
|
@ -303,22 +329,22 @@ impl Index {
|
||||||
.expect(&format!("missing header for block {}", expected_hash));
|
.expect(&format!("missing header for block {}", expected_hash));
|
||||||
|
|
||||||
// Index it
|
// Index it
|
||||||
let rows = index_block(&block, header.height());
|
let rows = index_block(block, header.height());
|
||||||
timer.tick("index");
|
timer.tick("index");
|
||||||
|
|
||||||
// Write to DB
|
// Write to DB
|
||||||
buf.write(rows);
|
buf.write(rows);
|
||||||
timer.tick("write");
|
timer.tick("write");
|
||||||
|
stats.update(block);
|
||||||
}
|
}
|
||||||
let block_count = bar.add(batch.len() as u64);
|
if bar.add(batch.len() as u64) % 10000 == 0 {
|
||||||
if block_count % 10000 == 0 {
|
debug!("index update {:?} {:?}", stats, timer);
|
||||||
debug!("index update ({} blocks) {:?}", block_count, timer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.flush(); // make sure no row is left behind
|
buf.flush(); // make sure no row is left behind
|
||||||
timer.tick("write");
|
timer.tick("write");
|
||||||
bar.finish();
|
bar.finish();
|
||||||
debug!("index update ({} blocks) {:?}", new_headers.len(), timer);
|
debug!("index update {:?} {:?}", stats, timer);
|
||||||
}
|
}
|
||||||
self.headers.write().unwrap().apply(new_headers);
|
self.headers.write().unwrap().apply(new_headers);
|
||||||
assert_eq!(tip, *self.headers.read().unwrap().tip());
|
assert_eq!(tip, *self.headers.read().unwrap().tip());
|
||||||
|
|
Loading…
Add table
Reference in a new issue