Skip to content

Conversation

@grahamking
Copy link
Contributor

@grahamking grahamking commented Jul 10, 2025

Performance work showed a drop-off in performance scaling when concurrency exceeds 16. Which is the number of threads we were giving tokio. Now we use all the cores on the machine which is the tokio default (and also what Go does).

Also ensure in most cases we only use a single tokio runtime. I still contend the secondary runtime is an unnecessary complication, but this way we preserve optionality (in case we choose to pin the secondary runtime to a single core), but also simplify the performance characteristics.

Summary by CodeRabbit

  • New Features

    • Added improved configuration options for runtime worker threads, allowing the number of worker threads to be automatically set based on available CPU cores if not specified.
    • Enhanced display formatting for runtime configuration, clearly indicating when default values are used.
  • Bug Fixes

    • Improved accuracy in documentation and comments regarding runtime behavior and configuration.
  • Chores

    • Updated internal logging for better runtime configuration visibility.
    • Minor documentation and formatting improvements.

Performance work showed a drop-off in performance scaling when
concurrency exceeds 16. Which is the number of threads we were giving
tokio. Now we use all the cores on the machine which is the tokio default
(and also what Go does).

Also ensure in most cases we only use a single tokio runtime. I still contend
the secondary runtime is an unnecessary complication, but this way we preserve
optionality (in case we choose to pin the secondary runtime to a single
core), but also simplify the performance characteristics.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 10, 2025

Walkthrough

The updates introduce optional worker thread configuration for the runtime, allowing it to default to the system's CPU core count when unset. Logging and display formatting for runtime configuration are enhanced. Runtime initialization logic is updated to support these changes, and documentation comments are clarified to accurately reflect runtime behavior.

Changes

File(s) Change Summary
launch/dynamo-run/src/main.rs Added debug log for runtime config after loading; updated comment about runtime wrapping behavior.
lib/runtime/src/config.rs Made num_worker_threads optional; updated docs; added Display impl; changed defaults to use CPU core count; updated tests and formatting.
lib/runtime/src/runtime.rs Updated runtime creation logic to use optional worker threads; improved logging; clarified and updated documentation comments.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Main
    participant RuntimeConfig
    participant Runtime

    User->>Main: Start application
    Main->>RuntimeConfig: Load settings
    RuntimeConfig-->>Main: Return config (num_worker_threads optional)
    Main->>Main: Log loaded config
    Main->>Runtime: Create runtime(s) with config
    Runtime->>RuntimeConfig: Use num_worker_threads or default to CPU cores
    Runtime-->>Main: Return initialized runtime(s)
Loading

Poem

In the meadow of code, a change takes root,
Worker threads now dance to a system-tuned flute.
Configs are clearer, logs shine bright,
Runtimes adapt to each core’s might.
With options and defaults, we hop ahead—
A rabbit’s delight in the code we’ve bred! 🐇


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1ae0f1 and ba422cc.

📒 Files selected for processing (3)
  • launch/dynamo-run/src/main.rs (1 hunks)
  • lib/runtime/src/config.rs (5 hunks)
  • lib/runtime/src/runtime.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
launch/dynamo-run/src/main.rs (1)
Learnt from: nnshah1
PR: ai-dynamo/dynamo#1444
File: tests/fault_tolerance/utils/metrics.py:30-32
Timestamp: 2025-07-01T13:55:03.940Z
Learning: The `@dynamo_worker()` decorator in the dynamo codebase returns a wrapper that automatically injects the `runtime` parameter before calling the wrapped function. This means callers only need to provide the non-runtime parameters, while the decorator handles injecting the runtime argument automatically. For example, a function with signature `async def get_metrics(runtime, log_dir)` decorated with `@dynamo_worker()` can be called as `get_metrics(log_dir)` because the decorator wrapper injects the runtime parameter.
lib/runtime/src/config.rs (3)
Learnt from: PeaBrane
PR: ai-dynamo/dynamo#1236
File: lib/llm/src/mocker/protocols.rs:85-112
Timestamp: 2025-06-16T20:02:54.935Z
Learning: When using derive_builder::Builder macro, the macro generates the builder struct and its methods, but does NOT generate a `builder()` method on the original struct. A manual `impl StructName { pub fn builder() -> StructNameBuilder { StructNameBuilder::default() } }` is required to provide the convenient `StructName::builder()` API pattern.
Learnt from: PeaBrane
PR: ai-dynamo/dynamo#1392
File: lib/llm/src/kv_router/scoring.rs:35-46
Timestamp: 2025-06-05T01:02:15.318Z
Learning: In lib/llm/src/kv_router/scoring.rs, PeaBrane prefers panic-based early failure over Result-based error handling for the worker_id() method to catch invalid data early during development.
Learnt from: jthomson04
PR: ai-dynamo/dynamo#1429
File: lib/runtime/src/utils/leader_worker_barrier.rs:69-72
Timestamp: 2025-06-08T03:12:03.985Z
Learning: In the leader-worker barrier implementation in lib/runtime/src/utils/leader_worker_barrier.rs, the `wait_for_key_count` function correctly uses exact equality (`==`) instead of greater-than-or-equal (`>=`) because worker IDs must be unique (enforced by etcd create-only operations), ensuring exactly the expected number of workers can register.
⏰ 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). (5)
  • GitHub Check: Mirror Repository to GitLab
  • GitHub Check: Build and Test - vllm
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
🔇 Additional comments (13)
launch/dynamo-run/src/main.rs (2)

65-65: Good addition for runtime visibility.

The debug logging will help with troubleshooting runtime configuration issues and provides useful visibility into the actual configuration being used.


67-67: Accurate comment update.

The comment correction from "two tokio runtimes" to "one or two tokio runtimes" accurately reflects the updated runtime creation logic where both primary and secondary runtimes can now share the same underlying Tokio runtime.

lib/runtime/src/runtime.rs (5)

50-50: Helpful debug logging for runtime creation.

The debug message provides useful visibility into when the fallback secondary runtime is created, which aids in troubleshooting runtime configuration.


64-64: Good simplification of from_current method.

Delegating to from_handle eliminates code duplication and maintains consistency in runtime creation logic.


68-70: Efficient runtime sharing implementation.

Creating both primary and secondary runtimes as External from the same handle effectively shares the underlying Tokio runtime, which aligns with the PR's goal of utilizing all available parallelism efficiently.


77-80: Optimal runtime configuration from settings.

The approach of creating a shared primary runtime and an external secondary runtime from the same handle maximizes resource utilization while maintaining the flexibility of having separate runtime handles for different purposes.


83-83: Accurate documentation update.

The comment correctly describes the method's intent to create two single-threaded runtimes, providing clear documentation for the API.

lib/runtime/src/config.rs (6)

58-62: Well-designed optional configuration.

Making num_worker_threads optional with automatic defaulting to CPU core count is an excellent design choice that allows the runtime to utilize all available parallelism by default while still permitting explicit configuration when needed.


93-108: Excellent Display implementation for configuration visibility.

The Display trait provides clear, readable output showing the configuration values, with helpful indication when num_worker_threads is using the default. This will be valuable for debugging and monitoring runtime setup.


175-184: Improved default configuration using CPU core count.

The updated Default implementation that uses available_parallelism() for both num_worker_threads and max_blocking_threads provides sensible defaults that scale with the hardware, which is much better than the previous fixed values.


153-153: Correct update for single-threaded configuration.

The change from num_worker_threads: 1 to num_worker_threads: Some(1) properly adapts to the new optional type while maintaining the intended single-threaded behavior.


259-259: Test properly updated for optional type.

The test assertion correctly expects Some(24) instead of 24 to match the new optional num_worker_threads type.


162-171: Approve create_runtime default behavior

The create_runtime method correctly defaults to available_parallelism() when num_worker_threads is unset. In practice, std::thread::available_parallelism() returns a non-zero count on supported platforms, so the .unwrap() is safe and no additional verification or fallback logic is needed.


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.

@grahamking grahamking enabled auto-merge (squash) July 10, 2025 15:42
@grahamking grahamking disabled auto-merge July 10, 2025 16:00
@grahamking grahamking merged commit da83f82 into main Jul 10, 2025
14 of 15 checks passed
@grahamking grahamking deleted the gk-more-threads branch July 10, 2025 16:03
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