Skip to content

Allocate multiple threads to column reconstruction task #7789

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

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
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
55 changes: 46 additions & 9 deletions beacon_node/beacon_processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ impl<E: EthSpec> Work<E> {
/// Unifies all the messages processed by the `BeaconProcessor`.
enum InboundEvent<E: EthSpec> {
/// A worker has completed a task and is free.
WorkerIdle,
WorkerIdle(WorkType),
/// There is new work to be done.
WorkEvent((WorkEvent<E>, Instant)),
/// A work event that was queued for re-processing has become ready.
Expand All @@ -761,8 +761,8 @@ impl<E: EthSpec> Stream for InboundEvents<E> {
// Always check for idle workers before anything else. This allows us to ensure that a big
// stream of new events doesn't suppress the processing of existing events.
match self.idle_rx.poll_recv(cx) {
Poll::Ready(Some(_)) => {
return Poll::Ready(Some(InboundEvent::WorkerIdle));
Poll::Ready(Some(work_type)) => {
return Poll::Ready(Some(InboundEvent::WorkerIdle(work_type)));
}
Poll::Ready(None) => {
return Poll::Ready(None);
Expand Down Expand Up @@ -934,8 +934,12 @@ impl<E: EthSpec> BeaconProcessor<E> {

loop {
let (work_event, created_timestamp) = match inbound_events.next().await {
Some(InboundEvent::WorkerIdle) => {
self.current_workers = self.current_workers.saturating_sub(1);
Some(InboundEvent::WorkerIdle(work_type)) => {
let threads_freed = match work_type {
WorkType::ColumnReconstruction => 4,
_ => 1,
};
self.current_workers = self.current_workers.saturating_sub(threads_freed);
(None, Instant::now())
}
Some(InboundEvent::WorkEvent((event, created_timestamp)))
Expand Down Expand Up @@ -1017,6 +1021,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
}

let can_spawn = self.current_workers < self.config.max_workers;
let can_spawn_extra_threads = self.current_workers < self.config.max_workers + 4;
let drop_during_sync = work_event
.as_ref()
.is_some_and(|event| event.drop_during_sync);
Expand Down Expand Up @@ -1255,7 +1260,25 @@ impl<E: EthSpec> BeaconProcessor<E> {

if let Some(work_event) = work_event {
let work_type = work_event.to_type();
self.spawn_worker(work_event, created_timestamp, idle_tx);
let thread_count = match work_type {
WorkType::ColumnReconstruction => 4,
_ => 1,
};
self.spawn_worker(work_event, idle_tx, thread_count, created_timestamp);
Some(work_type)
} else {
None
}
}
None if can_spawn_extra_threads => {
let work_event: Option<Work<E>> = column_reconstruction_queue.pop();
if let Some(work_event) = work_event {
let work_type = work_event.to_type();
let thread_count = match work_type {
WorkType::ColumnReconstruction => 4,
_ => 1,
};
self.spawn_worker(work_event, idle_tx, thread_count, created_timestamp);
Some(work_type)
} else {
None
Expand Down Expand Up @@ -1303,7 +1326,20 @@ impl<E: EthSpec> BeaconProcessor<E> {
)
}
}
_ if can_spawn => self.spawn_worker(work, created_timestamp, idle_tx),
_ if can_spawn => {
let thread_count = match work.to_type() {
WorkType::ColumnReconstruction => 4,
_ => 1,
};
self.spawn_worker(work, idle_tx, thread_count, created_timestamp);
}
_ if can_spawn_extra_threads => {
let thread_count = match work.to_type() {
WorkType::ColumnReconstruction => 4,
_ => 1,
};
self.spawn_worker(work, idle_tx, thread_count, created_timestamp)
}
Work::GossipAttestation { .. } => attestation_queue.push(work),
// Attestation batches are formed internally within the
// `BeaconProcessor`, they are not sent from external services.
Expand Down Expand Up @@ -1499,8 +1535,9 @@ impl<E: EthSpec> BeaconProcessor<E> {
fn spawn_worker(
&mut self,
work: Work<E>,
created_timestamp: Instant,
idle_tx: mpsc::Sender<WorkType>,
thread_count: usize,
created_timestamp: Instant,
) {
let work_id = work.str_id();
let work_type = work.to_type();
Expand Down Expand Up @@ -1531,7 +1568,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
};

let worker_id = self.current_workers;
self.current_workers = self.current_workers.saturating_add(1);
self.current_workers = self.current_workers.saturating_add(thread_count);

let executor = self.executor.clone();

Expand Down
Loading