From 8352623aed55ca29118beb46a6fc0c37188849df Mon Sep 17 00:00:00 2001 From: Yilin Chen Date: Tue, 9 Apr 2024 14:07:48 +0800 Subject: [PATCH] Workaround schedule_write_op busy loop issue (#412) Signed-off-by: Yilin Chen --- Cargo.toml | 1 + src/future/base_cache.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 9d283d13..57b87178 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,7 @@ smallvec = "1.8" tagptr = "0.2" thiserror = "1.0" uuid = { version = "1.1", features = ["v4"] } +tokio = { version = "1", features = ["rt"] } # Opt-out serde and stable_deref_trait features # https://github.com/Manishearth/triomphe/pull/5 diff --git a/src/future/base_cache.rs b/src/future/base_cache.rs index 5450b5b3..2229e422 100644 --- a/src/future/base_cache.rs +++ b/src/future/base_cache.rs @@ -655,6 +655,9 @@ where // We have got a `TrySendError::Full` above. Wait a moment and try again. + // Yield in case other `run_pending_tasks` cannot be scheduled by runtime. + tokio::task::yield_now().await; + if spin_loop_attempts < 4 { spin_loop_attempts += 1; // Wastes some CPU time with a hint to indicate to the CPU that we