Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(torii): different tasks for torii services #2552

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Oct 17, 2024

Summary by CodeRabbit

  • New Features

    • Improved concurrency for server components, allowing them to run independently and concurrently for enhanced responsiveness.
  • Bug Fixes

    • Simplified control flow in the main function for better task management.

Copy link

coderabbitai bot commented Oct 17, 2024

Walkthrough

Ohayo! This pull request modifies the main function in bin/torii/src/main.rs to enhance the concurrency model by spawning asynchronous tasks for multiple server components. The previous implementation, which utilized a tokio::select! block to await the completion of various servers, has been simplified. Now, the servers run concurrently without waiting for each other, improving responsiveness and parallel execution while maintaining the overall structure of the main function.

Changes

File Change Summary
bin/torii/src/main.rs Modified main function to spawn asynchronous tasks for engine, proxy_server, graphql_server, grpc_server, and libp2p_relay_server, removing direct awaits for these servers.

Possibly related PRs

  • feat(torii-core): parallelization #2423: The changes in this PR enhance concurrency capabilities in the main.rs file, which aligns with the main PR's focus on improving the concurrency model by utilizing tokio::spawn for asynchronous task handling.
  • opt(torii-core): move off queryqueue for executing tx #2460: This PR modifies the execution model for transactions, transitioning from a queue-based approach to an asynchronous message-passing model, which is related to the main PR's emphasis on concurrency improvements in the handling of server components.

Suggested reviewers

  • glihm

🪧 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 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

@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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 70ecca7 and 708e352.

📒 Files selected for processing (1)
  • bin/torii/src/main.rs (1 hunks)
🧰 Additional context used

bin/torii/src/main.rs Outdated Show resolved Hide resolved
bin/torii/src/main.rs Outdated Show resolved Hide resolved
Copy link

@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 and nitpick comments (1)
bin/torii/src/main.rs (1)

311-324: Ohayo, sensei! Great job on improving concurrency!

The changes to spawn separate tasks for each server component are a significant improvement. This approach allows for better concurrency and potentially improved performance. The separation of concerns is also cleaner now.

However, there are a few points to consider:

  1. Error handling: The current implementation uses ?? to propagate errors. Consider adding more robust error handling for each task.

  2. Resource management: With concurrent execution, be mindful of potential increased resource usage. You might want to add some resource limiting mechanisms if needed.

  3. Shutdown coordination: Ensure that all tasks shut down gracefully when the main select block exits.

Here's a suggestion to improve error handling:

-    let engine_handle = tokio::spawn(async move { engine.start().await });
+    let engine_handle = tokio::spawn(async move {
+        if let Err(e) = engine.start().await {
+            error!(target: LOG_TARGET, error = %e, "Engine encountered an error");
+        }
+    });

Apply similar changes to other task spawns for consistent error handling.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b5ddd99 and 655c401.

📒 Files selected for processing (1)
  • bin/torii/src/main.rs (1 hunks)
🧰 Additional context used

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Might be interesting to consider https://github.com/dojoengine/dojo/blob/main/crates/katana/tasks/src/manager.rs in a future rework on this part. 👍

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 69.53%. Comparing base (bdb8fb5) to head (4254279).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
bin/torii/src/main.rs 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2552      +/-   ##
==========================================
- Coverage   69.55%   69.53%   -0.03%     
==========================================
  Files         388      388              
  Lines       49964    49971       +7     
==========================================
- Hits        34752    34746       -6     
- Misses      15212    15225      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants