Skip to content

Commit 7ffa30b

Browse files
authored
Merge pull request #3298 from autonomys/improve-cluster-plotter-performance
Improve cluster plotter performance
2 parents 61b2625 + 8689b56 commit 7ffa30b

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

crates/subspace-farmer/src/plotter/gpu/gpu_encoders_manager.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ where
9696
let listener = event.listen();
9797

9898
if let Some(thread_pool_pair) = mutex.lock().pop() {
99-
drop(listener);
100-
// It is possible that we got here because there was the last free pair available
101-
// and in the meantime listener received notification. Just in case that was the
102-
// case, notify one more listener (if there is any) to make sure all available
103-
// thread pools are utilized when there is demand for them.
104-
event.notify(1);
10599
break thread_pool_pair;
106100
}
107101

crates/subspace-farmer/src/plotter/pool.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
33
use crate::plotter::{Plotter, SectorPlottingProgress};
44
use async_trait::async_trait;
5+
use event_listener::Event;
56
use futures::channel::mpsc;
7+
use futures::future;
68
use std::any::type_name_of_val;
9+
use std::pin::pin;
710
use std::time::Duration;
811
use subspace_core_primitives::sectors::SectorIndex;
912
use subspace_core_primitives::PublicKey;
@@ -18,6 +21,7 @@ use tracing::{error, trace};
1821
pub struct PoolPlotter {
1922
plotters: Vec<Box<dyn Plotter + Send + Sync>>,
2023
retry_interval: Duration,
24+
notification: Event,
2125
}
2226

2327
#[async_trait]
@@ -66,6 +70,7 @@ impl Plotter for PoolPlotter {
6670
)
6771
.await
6872
{
73+
self.notification.notify_relaxed(1);
6974
return;
7075
}
7176
}
@@ -74,7 +79,11 @@ impl Plotter for PoolPlotter {
7479
retry_interval = ?self.retry_interval,
7580
"All plotters are busy, will wait and try again later"
7681
);
77-
tokio::time::sleep(self.retry_interval).await;
82+
future::select(
83+
pin!(tokio::time::sleep(self.retry_interval)),
84+
self.notification.listen(),
85+
)
86+
.await;
7887
}
7988
}
8089

@@ -99,6 +108,7 @@ impl Plotter for PoolPlotter {
99108
)
100109
.await
101110
{
111+
self.notification.notify_relaxed(1);
102112
return true;
103113
}
104114
}
@@ -113,6 +123,7 @@ impl PoolPlotter {
113123
Self {
114124
plotters,
115125
retry_interval,
126+
notification: Event::new(),
116127
}
117128
}
118129
}

crates/subspace-farmer/src/thread_pool_manager.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ impl PlottingThreadPoolManager {
109109
let listener = event.listen();
110110

111111
if let Some(thread_pool_pair) = mutex.lock().thread_pool_pairs.pop() {
112-
drop(listener);
113-
// It is possible that we got here because there was the last free pair available
114-
// and in the meantime listener received notification. Just in case that was the
115-
// case, notify one more listener (if there is any) to make sure all available
116-
// thread pools are utilized when there is demand for them.
117-
event.notify(1);
118112
break thread_pool_pair;
119113
}
120114

0 commit comments

Comments
 (0)