Skip to content

Commit

Permalink
Limit reconstruction concurrency on farmer to avoid excessive memory …
Browse files Browse the repository at this point in the history
…usage
  • Loading branch information
nazar-pc committed Jun 29, 2023
1 parent 25ae19b commit c7e52c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/subspace-farmer-components/src/plotting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use subspace_core_primitives::{
use subspace_erasure_coding::ErasureCoding;
use subspace_proof_of_space::{Quality, Table};
use thiserror::Error;
use tokio::sync::Semaphore;
use tracing::{debug, warn};

fn default_backoff() -> ExponentialBackoff {
Expand Down Expand Up @@ -408,6 +409,10 @@ async fn download_sector<PG: PieceGetter>(
piece_indexes: &[PieceIndex],
piece_memory_cache: PieceMemoryCache,
) -> Result<(), PlottingError> {
// TODO: Make configurable, likely allowing user to specify RAM usage expectations and inferring
// concurrency from there
let recovery_semaphore = Semaphore::new(1);

let mut pieces_receiving_futures = piece_indexes
.iter()
.map(|piece_index| async {
Expand All @@ -428,6 +433,15 @@ async fn download_sector<PG: PieceGetter>(

// all retries failed
if !succeeded {
let _permit = match recovery_semaphore.acquire().await {
Ok(permit) => permit,
Err(error) => {
return (
piece_index,
Err(format!("Recovery semaphore was closed: {error}").into()),
);
}
};
let recovered_piece =
recover_missing_piece(piece_getter, kzg.clone(), piece_index).await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use thiserror::Error;
use tokio::sync::Semaphore;
use tracing::{debug, error, info, trace, warn};

// TODO: Probably should be made configurable
const PARALLELISM_LEVEL: usize = 20;

#[derive(Debug, Error)]
Expand Down

0 comments on commit c7e52c8

Please sign in to comment.