mirror of
https://github.com/romanz/electrs.git
synced 2025-02-24 15:02:21 +01:00
Add server loop-related metrics
This commit is contained in:
parent
1a8607bb73
commit
4508125ac1
1 changed files with 35 additions and 26 deletions
|
@ -77,6 +77,12 @@ fn serve() -> Result<()> {
|
||||||
"type",
|
"type",
|
||||||
metrics::default_size_buckets(),
|
metrics::default_size_buckets(),
|
||||||
);
|
);
|
||||||
|
let duration = metrics.histogram_vec(
|
||||||
|
"server_loop_duration",
|
||||||
|
"server loop duration",
|
||||||
|
"step",
|
||||||
|
metrics::default_duration_buckets(),
|
||||||
|
);
|
||||||
let mut rpc = Rpc::new(&config, metrics)?;
|
let mut rpc = Rpc::new(&config, metrics)?;
|
||||||
|
|
||||||
let new_block_rx = rpc.new_block_notification();
|
let new_block_rx = rpc.new_block_notification();
|
||||||
|
@ -84,8 +90,8 @@ fn serve() -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
// initial sync and compaction may take a few hours
|
// initial sync and compaction may take a few hours
|
||||||
while server_rx.is_empty() {
|
while server_rx.is_empty() {
|
||||||
let done = rpc.sync().context("sync failed")?; // sync a batch of blocks
|
let done = duration.observe_duration("sync", || rpc.sync().context("sync failed"))?; // sync a batch of blocks
|
||||||
peers = notify_peers(&rpc, peers); // peers are disconnected on error
|
peers = duration.observe_duration("notify", || notify_peers(&rpc, peers)); // peers are disconnected on error
|
||||||
if !done {
|
if !done {
|
||||||
continue; // more blocks to sync
|
continue; // more blocks to sync
|
||||||
}
|
}
|
||||||
|
@ -94,6 +100,7 @@ fn serve() -> Result<()> {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
duration.observe_duration("select", || -> Result<()> {
|
||||||
select! {
|
select! {
|
||||||
// Handle signals for graceful shutdown
|
// Handle signals for graceful shutdown
|
||||||
recv(rpc.signal().receiver()) -> result => {
|
recv(rpc.signal().receiver()) -> result => {
|
||||||
|
@ -114,10 +121,12 @@ fn serve() -> Result<()> {
|
||||||
let rest = server_rx.iter().take(server_rx.len());
|
let rest = server_rx.iter().take(server_rx.len());
|
||||||
let events: Vec<Event> = first.chain(rest).collect();
|
let events: Vec<Event> = first.chain(rest).collect();
|
||||||
server_batch_size.observe("recv", events.len() as f64);
|
server_batch_size.observe("recv", events.len() as f64);
|
||||||
handle_events(&rpc, &mut peers, events);
|
duration.observe_duration("handle", || handle_events(&rpc, &mut peers, events));
|
||||||
},
|
},
|
||||||
default(config.wait_duration) => (), // sync and update
|
default(config.wait_duration) => (), // sync and update
|
||||||
}
|
};
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue