Reduce load by not constantly spawning new threads for sleeping

This commit is contained in:
Neshura 2023-09-17 20:11:06 +02:00
parent 817f777059
commit ebbaed0973
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -86,9 +86,6 @@ async fn postgres_watchdog(pool: PgPool, is_alive: Arc<AtomicBool>, shutdown: Ar
println!("No Uptime Kuma URL provided!"); println!("No Uptime Kuma URL provided!");
} }
let passed = (Local::now() - start).to_std().expect(&format!("Unable to get Time Difference for '{}' and '{}'", start, Local::now()));
while Local::now() - start < chrono::Duration::seconds(15) { while Local::now() - start < chrono::Duration::seconds(15) {
sleep(Duration::from_millis(100)).await; sleep(Duration::from_millis(100)).await;
if shutdown.load(Ordering::Relaxed) { if shutdown.load(Ordering::Relaxed) {
@ -296,11 +293,7 @@ async fn main() -> Result<()> {
//watchdog_thread.await; //watchdog_thread.await;
while is_alive.load(Ordering::Relaxed) { while is_alive.load(Ordering::Relaxed) {
let thread = tokio::spawn(async { sleep(Duration::from_millis(200)).await;
let _ = sleep(Duration::from_millis(100));
});
let _ = thread.await;
} }
if shutdown.load(Ordering::Relaxed) { if shutdown.load(Ordering::Relaxed) {