Skip to content

Conversation

Teebor-Choka
Copy link
Contributor

Increase the number of concurrent streams allowed by the msg and ack protocols.

@Teebor-Choka Teebor-Choka added this to the 2.2.1 milestone Jan 23, 2025
@Teebor-Choka Teebor-Choka requested a review from a team January 23, 2025 12:37
@Teebor-Choka Teebor-Choka self-assigned this Jan 23, 2025
@Teebor-Choka Teebor-Choka marked this pull request as ready for review January 23, 2025 12:37
Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

📝 Walkthrough

Walkthrough

The pull request modifies the HoprNetworkBehavior struct in the transport/p2p/src/lib.rs file, specifically adjusting the configuration for maximum concurrent streams in the libp2p request-response mechanism. The change increases the default maximum concurrent streams from 1024 to 10240 for both message and acknowledgment behaviors, potentially allowing for more simultaneous network connections and improved network handling.

Changes

File Change Summary
transport/p2p/src/lib.rs Increased max concurrent streams from 1024 to 10240 for msg and ack behaviors in HoprNetworkBehavior::new() method

Possibly related PRs

Suggested labels

crate:core-p2p

Suggested reviewers

  • NumberFour8

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
transport/p2p/src/lib.rs (1)

Add load tests for concurrent streams configuration

The configuration is documented in README.md, but testing coverage could be improved:

  • Add load tests to verify behavior with high concurrent stream counts
  • Include test cases for environment variable configuration
  • Add tests to verify resource usage under maximum stream limits
🔗 Analysis chain

Line range hint 136-149: Add testing and documentation for increased concurrent streams.

To ensure reliability and maintainability:

  1. Add load tests to verify behavior with increased concurrent streams.
  2. Update documentation to:
    • Explain the rationale for 10240 concurrent streams
    • Document memory/resource requirements
    • Provide monitoring recommendations

Let's check for existing tests and documentation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Look for related tests
rg -l "test.*concurrent.*stream" --type rust

# Check documentation
fd -e md -e rst . | xargs rg -l "concurrent.*stream"

Length of output: 816


Script:

#!/bin/bash
# Check content of the found test file
echo "=== Mixer Test Content ==="
cat transport/protocol/src/msg/mixer.rs

# Look for integration tests
echo -e "\n=== Integration Tests ==="
fd -t f -e rs test integration

# Check for configuration documentation
echo -e "\n=== Configuration Documentation ==="
fd README.md | xargs rg -l "HOPR_INTERNAL_LIBP2P"
fd -e md -e toml . | xargs rg -l "concurrent.*streams"

Length of output: 4527


Script:

#!/bin/bash
# Look for integration tests correctly
echo "=== Integration Tests ==="
fd -e rs -t f . | rg "integration.*test"

# Look for configuration documentation
echo -e "\n=== Configuration Files and Docs ==="
# Check for environment variable documentation
rg -A 5 "HOPR_INTERNAL_LIBP2P" --type rust --type md --type toml

# Check for any config-related files
fd -e toml -e yaml -e env . | grep -i "config\|env"

Length of output: 5581

🧹 Nitpick comments (1)
transport/p2p/src/lib.rs (1)

149-149: Refactor duplicated configuration.

The same environment variable and default value (10240) are used for both msg and ack behaviors. Consider:

  1. Extracting the shared configuration into a constant or config struct.
  2. Using separate env vars if msg and ack behaviors might need different limits in the future.

Here's a suggested refactor:

+ /// Default maximum concurrent streams for libp2p request-response
+ const DEFAULT_MAX_CONCURRENT_STREAMS: usize = 10240;
+ 
+ /// Environment variable for message protocol concurrent streams
+ const ENV_MSG_MAX_STREAMS: &str = "HOPR_INTERNAL_LIBP2P_MSG_MAX_STREAMS";
+ 
+ /// Environment variable for acknowledgment protocol concurrent streams
+ const ENV_ACK_MAX_STREAMS: &str = "HOPR_INTERNAL_LIBP2P_ACK_MAX_STREAMS";

  msg: libp2p::request_response::cbor::Behaviour::<Box<[u8]>, ()>::new(
      // ...
      .with_max_concurrent_streams(
-         std::env::var("HOPR_INTERNAL_LIBP2P_MSG_ACK_MAX_TOTAL_STREAMS")
+         std::env::var(ENV_MSG_MAX_STREAMS)
              .and_then(|v| v.parse::<usize>().map_err(|_e| std::env::VarError::NotPresent))
-             .unwrap_or(1024 * 10),
+             .unwrap_or(DEFAULT_MAX_CONCURRENT_STREAMS),
      ),

  ack: libp2p::request_response::cbor::Behaviour::<Acknowledgement, ()>::new(
      // ...
      .with_max_concurrent_streams(
-         std::env::var("HOPR_INTERNAL_LIBP2P_MSG_ACK_MAX_TOTAL_STREAMS")
+         std::env::var(ENV_ACK_MAX_STREAMS)
              .and_then(|v| v.parse::<usize>().map_err(|_e| std::env::VarError::NotPresent))
-             .unwrap_or(1024 * 10),
+             .unwrap_or(DEFAULT_MAX_CONCURRENT_STREAMS),
      ),
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf58be5 and dc1b969.

📒 Files selected for processing (1)
  • transport/p2p/src/lib.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: hopli / docker
  • GitHub Check: hoprd / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-unit
  • GitHub Check: tests-smoke-websocket
  • GitHub Check: tests-smart-contracts
  • GitHub Check: Linter
🔇 Additional comments (1)
transport/p2p/src/lib.rs (1)

136-136: Consider resource management implications of increased concurrent streams.

While increasing concurrent streams from 1024 to 10240 aligns with the goal of handling VPN-like traffic, we should:

  1. Document the memory requirements per stream to help operators plan capacity.
  2. Consider adding memory monitoring/limits to prevent resource exhaustion.
  3. Extract the magic number (10240) into a named constant for better maintainability.

Let's verify the memory impact:

@Teebor-Choka Teebor-Choka merged commit ef9a52a into release/singapore Jan 23, 2025
37 of 43 checks passed
@Teebor-Choka Teebor-Choka deleted the kauki/vpn/allow-high-traffic-throughput-communication branch January 23, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants