1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-03-23 19:53:49 +03:00

add better performance around syncs

This commit is contained in:
Jonathan de Jong 2021-07-04 02:03:46 +02:00
parent 14e6afc45e
commit a55dec9035
2 changed files with 13 additions and 4 deletions
src
client_server
main.rs

View file

@ -144,6 +144,8 @@ pub async fn sync_helper_wrapper(
}
}
drop(db);
let _ = tx.send(Some(r.map(|(r, _)| r.into())));
}

View file

@ -32,7 +32,7 @@ use rocket::{
};
use tokio::{
sync::RwLock,
time::{interval, Interval},
time::{interval, timeout},
};
use tracing::span;
use tracing_subscriber::{prelude::*, Registry};
@ -211,18 +211,25 @@ async fn main() {
tokio::spawn(async {
let weak = weak;
let mut i = interval(Duration::from_secs(10));
let mut i = interval(Duration::from_secs(60));
loop {
i.tick().await;
if let Some(arc) = Weak::upgrade(&weak) {
log::warn!("wal-trunc: locking...");
let guard = arc.write().await;
let guard = {
if let Ok(guard) = timeout(Duration::from_secs(5), arc.write()).await {
guard
} else {
log::warn!("wal-trunc: lock failed in timeout, canceled.");
continue;
}
};
log::warn!("wal-trunc: locked, flushing...");
let start = Instant::now();
guard.flush_wal();
log::warn!("wal-trunc: locked, flushed in {:?}", start.elapsed());
log::warn!("wal-trunc: flushed in {:?}", start.elapsed());
} else {
break;
}