vacp2p / nim-libp2p

libp2p implementation in Nim
https://vacp2p.github.io/nim-libp2p/docs/
MIT License
242 stars 52 forks source link

Send priority with queue fix #1051

Closed arnetheduck closed 3 months ago

arnetheduck commented 4 months ago

This reapplies https://github.com/vacp2p/nim-libp2p/pull/1015 and is a smaller version of #1028 that focuses on clearing the priority queue at both ends since the completion order of send futures may be reversed.

The PR also introduces a workaround for redundant msg copies when sending encoded messages and ensures that sendMsg always returns a future that can be used for backpressure.

It creates two new metrics libp2p_gossipsub_priority_queue_size and libp2p_gossipsub_non_priority_queue_size that can be enabled with the pubsubpeer_queue_metrics flag. It should be used only locally as it is by peer and create a large amount of data.

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 87.90323% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 82.80%. Comparing base (2860959) to head (6eb23ca).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051/graphs/tree.svg?width=650&height=150&src=pr&token=UR5JRQ249W&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im)](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) ```diff @@ Coverage Diff @@ ## unstable #1051 +/- ## ============================================ + Coverage 82.77% 82.80% +0.02% ============================================ Files 91 91 Lines 15666 15749 +83 ============================================ + Hits 12968 13041 +73 - Misses 2698 2708 +10 ``` | [Files](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im) | Coverage Δ | | |---|---|---| | [libp2p/protocols/pubsub/floodsub.nim](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bGlicDJwL3Byb3RvY29scy9wdWJzdWIvZmxvb2RzdWIubmlt) | `87.60% <100.00%> (ø)` | | | [libp2p/protocols/pubsub/gossipsub.nim](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bGlicDJwL3Byb3RvY29scy9wdWJzdWIvZ29zc2lwc3ViLm5pbQ==) | `87.04% <100.00%> (+0.14%)` | :arrow_up: | | [libp2p/protocols/pubsub/pubsub.nim](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bGlicDJwL3Byb3RvY29scy9wdWJzdWIvcHVic3ViLm5pbQ==) | `84.29% <100.00%> (+1.53%)` | :arrow_up: | | [libp2p/protocols/pubsub/gossipsub/behavior.nim](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bGlicDJwL3Byb3RvY29scy9wdWJzdWIvZ29zc2lwc3ViL2JlaGF2aW9yLm5pbQ==) | `88.83% <75.00%> (ø)` | | | [libp2p/protocols/pubsub/pubsubpeer.nim](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im#diff-bGlicDJwL3Byb3RvY29scy9wdWJzdWIvcHVic3VicGVlci5uaW0=) | `88.97% <85.41%> (-1.94%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/status-im/nim-libp2p/pull/1051/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=status-im)