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

[Optimize] Adjust blocking tasks in the primary #3121

Merged
merged 1 commit into from
Mar 2, 2024

Conversation

ljedrz
Copy link
Collaborator

@ljedrz ljedrz commented Feb 23, 2024

This PR adjusts the placement of blocking tasks in the primary module based on how long the blocking operations can take, so that we avoid blocking the async executor.

@@ -630,7 +630,7 @@ impl<N: Network> Primary<N> {
let BatchSignature { batch_id, signature } = batch_signature;

// Retrieve the signer.
let signer = spawn_blocking!(Ok(signature.to_address()))?;
let signer = signature.to_address();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this operation was found to be fast enough to not require blocking

@ljedrz ljedrz force-pushed the perf/adjust_blocking_primary branch from 32f3774 to 93768f6 Compare February 23, 2024 15:20
@@ -1114,7 +1119,7 @@ impl<N: Network> Primary<N> {
/// Stores the certified batch and broadcasts it to all validators, returning the certificate.
async fn store_and_broadcast_certificate(&self, proposal: &Proposal<N>, committee: &Committee<N>) -> Result<()> {
// Create the batch certificate and transmissions.
let (certificate, transmissions) = proposal.to_certificate(committee)?;
let (certificate, transmissions) = tokio::task::block_in_place(|| proposal.to_certificate(committee))?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is done via block_in_place instead of spawn_blocking in order to not have to clone the Proposal, which could get expensive enough to defeat the purpose

Signed-off-by: ljedrz <ljedrz@gmail.com>
@ljedrz ljedrz force-pushed the perf/adjust_blocking_primary branch from 93768f6 to 86acd1d Compare February 23, 2024 15:41
@@ -1840,7 +1845,7 @@ mod tests {
);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is a requirement for using block_in_place

@ljedrz
Copy link
Collaborator Author

ljedrz commented Mar 1, 2024

These changes were tested using tokio-console and 4 validators in --dev mode; the code of the non-blocking Primary-related tasks that were showing high busy values was investigated for the presence of blocking operations, and once those were put inside blocking tasks, the busy values have dropped, meaning the async worker threads and the executor were no longer being blocked (i.e. slowed down).

@howardwu howardwu merged commit dd173f7 into AleoNet:mainnet Mar 2, 2024
23 of 24 checks passed
@howardwu howardwu changed the title Adjust blocking tasks in the primary [Optimize] Adjust blocking tasks in the primary Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants