Skip to content

Conversation

@alec-flowers
Copy link
Contributor

@alec-flowers alec-flowers commented Jul 30, 2025

Overview:

Cherry-pick #2175

Summary by CodeRabbit

  • New Features

    • Added support for configuring a custom port range for Dynamo services via new command-line options.
    • Improved port allocation by ensuring consecutive ports can be reserved for side channel communication.
    • Enhanced error handling and validation for port allocation.
  • Refactor

    • Centralized and modularized port allocation logic into a dedicated module for better maintainability and reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

The changes modularize and refactor port allocation logic for Dynamo services by moving it from args.py into a new ports.py module. The new module introduces structured classes and functions for port range configuration, ETCD-backed port reservation, and block allocation. Argument parsing and configuration are updated to utilize these abstractions.

Changes

Cohort / File(s) Change Summary
Port Allocation Refactor in Args
components/backends/vllm/src/dynamo/vllm/args.py
Removes internal port allocation logic, imports new abstractions and utilities from ports.py, updates configuration and argument parsing to support explicit port range, and refactors port allocation to use new module functions.
New Port Allocation Module
components/backends/vllm/src/dynamo/vllm/ports.py
Introduces a new module with classes and functions for port range definition, ETCD context, port metadata, port allocation requests, socket-level port holding, ETCD-backed reservation, block allocation, and host IP resolution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ArgsParser
    participant Config
    participant PortsModule
    participant Etcd

    User->>ArgsParser: Provide CLI args (including port min/max)
    ArgsParser->>Config: Create Config with port_range
    Config->>PortsModule: Request port allocation (KV/side channel)
    PortsModule->>Etcd: Reserve port(s) in ETCD
    PortsModule->>Config: Return allocated port(s)
    Config->>User: Configuration ready with allocated ports
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • fix: add better port logic #2175: Refactors and modularizes port allocation logic, introducing the abstractions and mechanisms that are now integrated into args.py via the new ports.py module.

Poem

In burrows deep, the ports were wild,
Now gathered neat, they're tamed and filed.
ETCD keeps watch, allocation's fair,
No more race for sockets—just fresh, open air!
With each new hop, the code grows bright,
A rabbit's joy: ports managed right! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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

🧹 Nitpick comments (2)
components/backends/vllm/src/dynamo/vllm/ports.py (1)

142-227: Excellent implementation of atomic port block allocation.

The function implements a robust allocation strategy with proper validation, atomic operations, and retry logic. The use of hold_ports context manager ensures exclusive access during ETCD reservation, preventing race conditions.

Consider making the retry sleep duration configurable or using exponential backoff instead of a fixed 0.01s delay to better handle high contention scenarios:

-        if attempt < actual_max_attempts:
-            await asyncio.sleep(0.01)
+        if attempt < actual_max_attempts:
+            # Exponential backoff with jitter
+            await asyncio.sleep(min(0.01 * (2 ** (attempt - 1)) + random.uniform(0, 0.01), 1.0))
components/backends/vllm/src/dynamo/vllm/args.py (1)

234-234: Address the TODO comment about KV port calculation.

The comment indicates this is a workaround for vLLM's behavior. This should be tracked and fixed properly in vLLM to avoid confusion.

Would you like me to create an issue to track fixing this in vLLM so the workaround can be removed?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b69c507 and d5a204e.

📒 Files selected for processing (2)
  • components/backends/vllm/src/dynamo/vllm/args.py (5 hunks)
  • components/backends/vllm/src/dynamo/vllm/ports.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (13)
components/backends/vllm/src/dynamo/vllm/ports.py (9)

1-23: LGTM!

The module setup with appropriate imports and well-defined constants for the default port range is clean and follows best practices.


25-41: Well-designed dataclass with proper validation.

The DynamoPortRange dataclass correctly validates that ports are within the registered ports range (1024-49151) and that min < max. The error messages are clear and informative.


43-54: Clean abstraction for ETCD operations.

The EtcdContext dataclass provides a clean abstraction for ETCD operations with a well-structured key format that includes namespace and node IP for proper isolation.


56-75: Well-structured metadata with useful debugging information.

The PortMetadata dataclass properly captures essential information about port reservations, including timestamp and PID for debugging. Good use of field(default_factory=dict) for the mutable default.


88-114: Robust context manager for exclusive port access.

The hold_ports context manager correctly handles both single and multiple ports, uses SO_REUSEADDR for port reuse, and ensures proper cleanup with the finally block.


116-124: Simple and effective port availability check.

The function correctly uses a context manager to ensure socket cleanup and appropriately catches OSError for bind failures.


126-140: Clean ETCD reservation implementation.

The function properly reserves ports in ETCD with JSON-encoded metadata and uses the primary lease ID for automatic cleanup on process termination.


229-261: Clean convenience wrapper for single port allocation.

The function effectively reuses the block allocation logic for single ports, maintaining consistency and reducing code duplication.


263-291: Robust host IP detection with comprehensive error handling.

The function properly handles various failure scenarios (hostname resolution, binding failures) with appropriate fallbacks and informative logging. The bindability test is a smart addition to ensure the resolved IP is actually usable.

components/backends/vllm/src/dynamo/vllm/args.py (4)

15-26: Clean import of port management utilities.

The imports from the new ports module are well-organized and all imported items are utilized in the refactored code.


44-44: Good addition of port range configuration.

Adding the port_range attribute to the Config class properly encapsulates the port range configuration.


75-86: Well-implemented command-line arguments for port range configuration.

The new --dynamo-port-min and --dynamo-port-max arguments have sensible defaults, clear help text, and proper validation through the DynamoPortRange constructor.

Also applies to: 133-135


146-202: Port allocation logic verified and approved

All NIXL port calculations match the documented formula (base_port + dp_rank*tp_size + tp_rank), and the code correctly allocates a contiguous block, computes the base port, and guards against negative values. A search of the repo shows no other NIXL connector implementation that would conflict. No further changes needed.

@alec-flowers alec-flowers enabled auto-merge (squash) July 30, 2025 19:21
@dmitry-tokarev-nv dmitry-tokarev-nv merged commit 992adfb into release/0.4.0 Jul 30, 2025
16 checks passed
@dmitry-tokarev-nv dmitry-tokarev-nv deleted the aflowers/0.4.0-port-bugfix branch July 30, 2025 21:07
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