Skip to content

Commit

Permalink
feat: make log-slow-write-lock timeout configurable
Browse files Browse the repository at this point in the history
the code now reads env var:
LOG_SLOW_WRITE_LOCK_THRESHOLD

which takes decimal seconds.

eg:
LOG_SLOW_WRITE_LOCK_THRESHOLD=0.0001
  • Loading branch information
dan-da committed Nov 4, 2024
1 parent de96f98 commit 2d0be8f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/locks/tokio/atomic_rw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,16 @@ impl<T> Drop for AtomicRwWriteGuard<'_, T> {
#[cfg(feature = "log-slow-write-lock")]
{
let duration = self.timestamp.elapsed();
let max_duration_milli = 100;
if duration.as_millis() > max_duration_milli {
let max_duration_secs = match std::env::var("LOG_SLOW_WRITE_LOCK_THRESHOLD") {
Ok(t) => t.parse().unwrap(),
Err(_) => 0.1,
};

if duration.as_secs_f32() > max_duration_secs {
tracing::warn!(
"write-lock held for {} seconds. (exceeds max: {} milli) location: {}",
"write-lock held for {} seconds. (exceeds max: {} secs) location: {}",
duration.as_secs_f32(),
max_duration_milli,
max_duration_secs,
self.location
);
}
Expand Down

0 comments on commit 2d0be8f

Please sign in to comment.