Skip to content

Commit

Permalink
feat: batch size depends on CPU count
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Oct 28, 2024
1 parent b3f6c91 commit e8e16b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions autonomi/src/client/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ use bytes::Bytes;
use sn_evm::EvmWallet;
use sn_networking::target_arch::{Duration, SystemTime};
use std::path::PathBuf;
use std::sync::LazyLock;
use tokio::task::JoinError;

use super::archive::{Archive, ArchiveAddr};
use super::data::{DataAddr, GetError, PutError};

pub(crate) const FILE_UPLOAD_BATCH_SIZE: usize = 128;
/// Number of files to upload in parallel.
pub static FILE_UPLOAD_BATCH_SIZE: LazyLock<usize> = LazyLock::new(|| {
std::thread::available_parallelism()
.map(|n| n.get())
.unwrap_or(1)
* 16
});

/// Errors that can occur during the file upload operation.
#[cfg(feature = "fs")]
Expand Down Expand Up @@ -123,7 +130,7 @@ impl Client {

// wait for all files to be uploaded
let uploads =
process_tasks_with_max_concurrency(upload_tasks, FILE_UPLOAD_BATCH_SIZE).await?;
process_tasks_with_max_concurrency(upload_tasks, *FILE_UPLOAD_BATCH_SIZE).await?;
info!(
"Upload of {} files completed in {:?}",
uploads.len(),
Expand Down
2 changes: 1 addition & 1 deletion autonomi/src/client/fs_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Client {

// wait for all files to be uploaded
let uploads =
process_tasks_with_max_concurrency(upload_tasks, FILE_UPLOAD_BATCH_SIZE).await?;
process_tasks_with_max_concurrency(upload_tasks, *FILE_UPLOAD_BATCH_SIZE).await?;
info!(
"Upload of {} files completed in {:?}",
uploads.len(),
Expand Down

0 comments on commit e8e16b7

Please sign in to comment.