Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
feat(concurrency): implement Default for ConcurrencyConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
barak-b-starkware committed Jun 4, 2024
1 parent 4642dca commit 53ff368
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use crate::concurrency::utils::{DEFAULT_CHUNK_SIZE, DEFAULT_N_WORKERS};

#[derive(Debug, Default, Clone)]
pub struct TransactionExecutorConfig {
pub concurrency_config: ConcurrencyConfig,
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Clone)]
pub struct ConcurrencyConfig {
pub enabled: bool,
pub n_workers: usize,
pub chunk_size: usize,
}

impl Default for ConcurrencyConfig {
fn default() -> Self {
Self { enabled: true, n_workers: DEFAULT_N_WORKERS, chunk_size: DEFAULT_CHUNK_SIZE }
}
}
3 changes: 1 addition & 2 deletions crates/blockifier/src/concurrency/scheduler_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use pretty_assertions::assert_eq;
use rstest::rstest;

use crate::concurrency::scheduler::{Scheduler, Task, TransactionStatus};
use crate::concurrency::utils::DEFAULT_CHUNK_SIZE;
use crate::concurrency::TxIndex;
use crate::default_scheduler;

const DEFAULT_CHUNK_SIZE: usize = 100;

#[rstest]
fn test_new(#[values(0, 1, 32)] chunk_size: usize) {
let scheduler = Scheduler::new(chunk_size);
Expand Down
5 changes: 5 additions & 0 deletions crates/blockifier/src/concurrency/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ pub fn lock_mutex_in_array<T: Debug>(array: &[Mutex<T>], tx_index: TxIndex) -> M
panic!("Cell of transaction index {} is poisoned. Data: {:?}.", tx_index, *error.get_ref())
})
}

// Constants.

pub const DEFAULT_CHUNK_SIZE: usize = 64;
pub const DEFAULT_N_WORKERS: usize = 4;

0 comments on commit 53ff368

Please sign in to comment.