-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transport: Fix waking up on filtered events from
poll_next
(#287)
This PR ensures that the transport (TCP / WebSocket) implementation wakes up the waker `FuturesUnordered` on adding futures to the set. This is one of the async rough edges in Rust, to properly illustrate the issue I've compiled this rust example (comment and uncomment like 43 to see the issue in action): ### Example 1 The future is not polled again: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1e801c4864599c54a98bb9f30be1fdd5 ### Example 2 The future is delayed (from 2s to 3s) because it relies on some other implementation to wake up the context waker: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=951080892763ca7d02ae9c5617da6c5d ### Particular implementation The `poll_next` implementation polls 3 objects: - `listener`: accepts incoming socket connections - `pending_raw_connections`: dialing futures to establish socket connection - `pending_connections`: negotiating futures to establish libp2p protocols When adding futures to either `pending_raw_connections` or `pending_connections`, the futures are not polled immediately. Instead, they will get polled the first time an already present future finishes execution. This effectively leads to delays in processing both raw connections and pending connections. This PR in combination with #286 has improved the connection stability of litep2p for a high number of connections (500 in and 500 out). The decreasing line represents release 0.8 configured with 500 in and out peers, while the stable line from 11/12 represents litep2p with incoming PR patches. (I've restarted the node 3/4 times for more debug logs): ![Screenshot 2024-11-12 at 14 49 43](https://github.com/user-attachments/assets/01d7f864-e219-4bed-b798-bd84b4356522) ### Next Steps - There are a few other places were this may be happening, I'll have a look at them after we sort out connection limits. - @dmitry-markin suggested an even more optimized way of handling this by polling each future individually to feed them a context waker before adding to the inner FuturesUnordered 🙏 --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
- Loading branch information
Showing
8 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ pub mod yamux; | |
|
||
mod bandwidth; | ||
mod multistream_select; | ||
mod utils; | ||
|
||
#[cfg(test)] | ||
mod mock; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2024 litep2p developers | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the "Software"), | ||
// to deal in the Software without restriction, including without limitation | ||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
// and/or sell copies of the Software, and to permit persons to whom the | ||
// Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
pub mod futures_stream; |