mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +00:00
add better performance around syncs
This commit is contained in:
parent
14e6afc45e
commit
a55dec9035
2 changed files with 13 additions and 4 deletions
|
@ -144,6 +144,8 @@ pub async fn sync_helper_wrapper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(db);
|
||||||
|
|
||||||
let _ = tx.send(Some(r.map(|(r, _)| r.into())));
|
let _ = tx.send(Some(r.map(|(r, _)| r.into())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -32,7 +32,7 @@ use rocket::{
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::RwLock,
|
sync::RwLock,
|
||||||
time::{interval, Interval},
|
time::{interval, timeout},
|
||||||
};
|
};
|
||||||
use tracing::span;
|
use tracing::span;
|
||||||
use tracing_subscriber::{prelude::*, Registry};
|
use tracing_subscriber::{prelude::*, Registry};
|
||||||
|
@ -211,18 +211,25 @@ async fn main() {
|
||||||
tokio::spawn(async {
|
tokio::spawn(async {
|
||||||
let weak = weak;
|
let weak = weak;
|
||||||
|
|
||||||
let mut i = interval(Duration::from_secs(10));
|
let mut i = interval(Duration::from_secs(60));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
i.tick().await;
|
i.tick().await;
|
||||||
|
|
||||||
if let Some(arc) = Weak::upgrade(&weak) {
|
if let Some(arc) = Weak::upgrade(&weak) {
|
||||||
log::warn!("wal-trunc: locking...");
|
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...");
|
log::warn!("wal-trunc: locked, flushing...");
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
guard.flush_wal();
|
guard.flush_wal();
|
||||||
log::warn!("wal-trunc: locked, flushed in {:?}", start.elapsed());
|
log::warn!("wal-trunc: flushed in {:?}", start.elapsed());
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue