-
Notifications
You must be signed in to change notification settings - Fork 106
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
Async in Zebra RFC #1965
Async in Zebra RFC #1965
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, i made a few suggestions as i will like to see the RFC as a reference guide where the developer/reviewer can refer to specific sections where the rules are set.
I think we're ready for a final review now. |
This RFC is now ready for another round of review. Here's what I changed since the last reviews:
Here are the changes since @oxarbitrage and @dconnolly last reviewed: |
Zebra's [`Inbound service`](https://github.com/ZcashFoundation/zebra/blob/0203d1475a95e90eb6fd7c4101caa26aeddece5b/zebrad/src/components/inbound.rs#L238) | ||
can't use an async-aware mutex for its `AddressBook`, because the mutex is shared | ||
with non-async code. It only holds the mutex to clone the address book, reducing | ||
the amount of time that other tasks on its thread are blocked: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename xxxx-async-rust.md
to 0011-async-rust.md
and move out from drafts folder.
Rest looks good.
@conradoplg you might also want to read the examples in this RFC. It should help you write or troubleshoot async Rust. |
Feel free to ask questions, and let me know if anything is unclear. |
@oxarbitrage I moved and renamed the file, this PR will auto-squash and merge once you approve it. |
If the lock isn't dropped, compilation fails, because the mutex lock can't be | ||
sent between threads. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
If you are unable to use futures-aware types: | ||
- block the thread for as short a time as possible | ||
- document the correctness of each blocking call | ||
- consider re-designing the code to use `tower::Services`, or other futures-aware types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
- make critical sections as short as possible, and | ||
- do not depend on other tasks or locks inside the critical section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
In Zebra, we try to use safe abstractions, and write obviously correct code. It takes | ||
a lot of effort to write, test, and maintain low-level code. Almost all of our | ||
performance-critical code is in cryptographic libraries. And our biggest performance | ||
gains from those libraries come from async batch cryptography. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💖
@@ -505,3 +679,6 @@ those bugs can take a lot of developer effort. | |||
Can we catch these bugs using automated tests? | |||
|
|||
How can we diagnose these kinds of issues faster and more reliably? | |||
- [TurboWish](https://blog.pnkfx.org/blog/2021/04/26/road-to-turbowish-part-1-goals/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
TODO
Mutex
imports, e.g.std::sync::Mutex
orfutures::lock::Mutex
futures::lock::Mutex
in async functions or blocksstd::sync::Mutex
in async code, hold the mutex for as short a time as possibleSummary
Zebra executes concurrent tasks using async Rust, with the tokio executor.
At a higher level, Zebra also uses
tower::Service
s,tower::Buffer
s, and our owntower-batch
implementation.Zebra programmers need to carefully write async code so it doesn't deadlock or hang. This is particularly important for
poll
,select
,Buffer
, andBatch
.More information
Document
Rendered
Zebra Team Approval
Everyone on the Zebra team should review design RFCs:
If no-one has time to review by 2021-04-09, let's merge this RFC as a draft.
Related Tickets
Closes #1593.