Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cluster plotter performance #3298

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ where
let listener = event.listen();

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

Expand Down
13 changes: 12 additions & 1 deletion crates/subspace-farmer/src/plotter/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

use crate::plotter::{Plotter, SectorPlottingProgress};
use async_trait::async_trait;
use event_listener::Event;
use futures::channel::mpsc;
use futures::future;
use std::any::type_name_of_val;
use std::pin::pin;
use std::time::Duration;
use subspace_core_primitives::sectors::SectorIndex;
use subspace_core_primitives::PublicKey;
Expand All @@ -18,6 +21,7 @@ use tracing::{error, trace};
pub struct PoolPlotter {
plotters: Vec<Box<dyn Plotter + Send + Sync>>,
retry_interval: Duration,
notification: Event,
}

#[async_trait]
Expand Down Expand Up @@ -66,6 +70,7 @@ impl Plotter for PoolPlotter {
)
.await
{
self.notification.notify_relaxed(1);
return;
}
}
Expand All @@ -74,7 +79,11 @@ impl Plotter for PoolPlotter {
retry_interval = ?self.retry_interval,
"All plotters are busy, will wait and try again later"
);
tokio::time::sleep(self.retry_interval).await;
future::select(
pin!(tokio::time::sleep(self.retry_interval)),
self.notification.listen(),
)
.await;
}
}

Expand All @@ -99,6 +108,7 @@ impl Plotter for PoolPlotter {
)
.await
{
self.notification.notify_relaxed(1);
return true;
}
}
Expand All @@ -113,6 +123,7 @@ impl PoolPlotter {
Self {
plotters,
retry_interval,
notification: Event::new(),
}
}
}
6 changes: 0 additions & 6 deletions crates/subspace-farmer/src/thread_pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ impl PlottingThreadPoolManager {
let listener = event.listen();

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

Expand Down
Loading