mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 00:59:07 -05:00
perf: shed DB query load when queue gets large
This commit is contained in:
parent
dc11d9a619
commit
1c153bc784
12
src/db.rs
12
src/db.rs
|
@ -647,8 +647,16 @@ pub async fn db_query(
|
||||||
let pre_spawn_start = Instant::now();
|
let pre_spawn_start = Instant::now();
|
||||||
task::spawn_blocking(move || {
|
task::spawn_blocking(move || {
|
||||||
let db_queue_time = pre_spawn_start.elapsed();
|
let db_queue_time = pre_spawn_start.elapsed();
|
||||||
// report queuing time if it is slow
|
// if the queue time was very long (>5 seconds), spare the DB and abort.
|
||||||
if db_queue_time > Duration::from_secs(1) {
|
if db_queue_time > Duration::from_secs(5) {
|
||||||
|
info!(
|
||||||
|
"shedding DB query load from {:?} (cid: {}, sub: {:?})",
|
||||||
|
db_queue_time, client_id, sub.id
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
// otherwise, report queuing time if it is slow
|
||||||
|
else if db_queue_time > Duration::from_secs(1) {
|
||||||
debug!(
|
debug!(
|
||||||
"(slow) DB query queued for {:?} (cid: {}, sub: {:?})",
|
"(slow) DB query queued for {:?} (cid: {}, sub: {:?})",
|
||||||
db_queue_time, client_id, sub.id
|
db_queue_time, client_id, sub.id
|
||||||
|
|
Loading…
Reference in New Issue
Block a user