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

Move network transaction deserialization to a dedicated blocking and CPU-heavy thread #4787

Closed
teor2345 opened this issue Jul 18, 2022 · 0 comments · Fixed by #4801
Closed
Assignees
Labels
A-cryptography Area: Cryptography related A-network Area: Network protocol updates or fixes C-bug Category: This is a bug I-integration-fail Continuous integration fails, including build and test failures I-slow Problems with performance or responsiveness

Comments

@teor2345
Copy link
Contributor

teor2345 commented Jul 18, 2022

Motivation

Zebra's sync can be slow or fail, because transaction deserialization involves some CPU-heavy cryptography.

So we want to move transaction deserialization into a rayon CPU thread pool scope.

API Reference

Blocking threads:
https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.html

CPU-heavy threads:
https://docs.rs/rayon/latest/rayon/fn.scope_fifo.html

Detailed Analysis

See #4583 (comment)

Designs

When zebra-network deserializes a block or transaction, move that work to the rayon thread pool.

Example code for rayon in tokio blocking threads:

/// Flush the batch using a thread pool, and return the result via the channel.
/// This function returns a future that becomes ready when the batch is completed.
fn flush_spawning(batch: BatchVerifier, tx: Sender) -> impl Future<Output = ()> {
// Correctness: Do CPU-intensive work on a dedicated thread, to avoid blocking other futures.
tokio::task::spawn_blocking(|| {
// TODO:
// - spawn batches so rayon executes them in FIFO order
// possible implementation: return a closure in a Future,
// then run it using scope_fifo() in the worker task,
// limiting the number of concurrent batches to the number of rayon threads
rayon::scope_fifo(|s| s.spawn_fifo(|_s| Self::verify(batch, tx)))
})
.map(|join_result| join_result.expect("panic in ed25519 batch verifier"))
}

Related Work

State deserialization is handled in #4788

@teor2345 teor2345 added C-bug Category: This is a bug S-needs-triage Status: A bug report needs triage labels Jul 18, 2022
@teor2345 teor2345 changed the title Move transaction deserialization to a dedicated CPU-heavy thread Move transaction deserialization to a dedicated blokcing and CPU-heavy thread Jul 18, 2022
@teor2345 teor2345 added P-High 🔥 I-slow Problems with performance or responsiveness I-integration-fail Continuous integration fails, including build and test failures A-cryptography Area: Cryptography related labels Jul 18, 2022
@teor2345 teor2345 changed the title Move transaction deserialization to a dedicated blokcing and CPU-heavy thread Move transaction deserialization to a dedicated blocking and CPU-heavy thread Jul 18, 2022
@teor2345 teor2345 changed the title Move transaction deserialization to a dedicated blocking and CPU-heavy thread Move network transaction deserialization to a dedicated blocking and CPU-heavy thread Jul 18, 2022
@teor2345 teor2345 added the A-network Area: Network protocol updates or fixes label Jul 18, 2022
@ftm1000 ftm1000 removed the S-needs-triage Status: A bug report needs triage label Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cryptography Area: Cryptography related A-network Area: Network protocol updates or fixes C-bug Category: This is a bug I-integration-fail Continuous integration fails, including build and test failures I-slow Problems with performance or responsiveness
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants