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

use arc for broadcast channels #1216

Conversation

Victor-M-Giraldo
Copy link
Contributor

@Victor-M-Giraldo Victor-M-Giraldo commented Jan 11, 2024

closes #1199

Summary by CodeRabbit

  • Refactor
    • Enhanced the transaction broadcasting mechanism for improved stability and performance.

Copy link
Contributor

coderabbitai bot commented Jan 11, 2024

Important

Auto Review Skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The update involves wrapping the broadcast_tx variable in an Arc to optimize memory usage when broadcasting messages to clients in a room. This change aims to reduce the need for cloning the message for each client, thereby decreasing memory allocations and potentially improving performance.

Changes

File Path Change Summary
.../ott-balancer/src/monolith.rs Changed broadcast_tx type to Arc<tokio::sync::broadcast::Sender<SocketMessage>> and used Arc::new for initialization.

Assessment against linked issues

Objective Addressed Explanation
Use Arc for room broadcast channels (#1199) The change to wrap broadcast_tx with an Arc aligns with the objective to minimize memory cloning.

Poem

As the messages fly, swift and wide,
A clever rabbit thought to provide,
An Arc to hold them side by side,
Less cloning, more pride, in every byte!

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7b1e287 and 1400866.
Files selected for processing (1)
  • crates/ott-balancer/src/monolith.rs (2 hunks)
Additional comments: 1
crates/ott-balancer/src/monolith.rs (1)
  • 149-155: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [152-162]

The use of Arc to wrap the broadcast_tx sender in the Room struct is consistent with the PR's objective to optimize memory usage by allowing shared ownership of the broadcast sender. This change should reduce the number of clones created when broadcasting messages to multiple clients.

However, ensure that all parts of the code that interact with broadcast_tx are updated to work with the Arc wrapped type. This includes any external modules or tests that may rely on the previous type signature.

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5d7baad) 61.5318% compared to head (190d4dc) 61.6880%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master      #1216        +/-   ##
================================================
+ Coverage   61.5318%   61.6880%   +0.1561%     
================================================
  Files           115        115                
  Lines          9322       9360        +38     
  Branches       1141       1142         +1     
================================================
+ Hits           5736       5774        +38     
  Misses         3586       3586                

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

@Victor-M-Giraldo
Copy link
Contributor Author

Do you know why the cypress tests fail? I took a look at the logs and it seems like they are failing to fetch the imported modules for the component tests, and it can't find a .video button for the e2e tests.

@Victor-M-Giraldo
Copy link
Contributor Author

Also, do you know if it would it be better to use into() to change the type of broadcast_tx as opposed to using new() or does it not matter too much?

Does one use more memory as opposed to the other?

crates/ott-balancer/src/monolith.rs Outdated Show resolved Hide resolved
@dyc3
Copy link
Owner

dyc3 commented Jan 12, 2024

Do you know why the cypress tests fail?

It's completely out of our control, and its really annoying. See cypress-io/cypress#25913

@Victor-M-Giraldo Victor-M-Giraldo marked this pull request as draft January 12, 2024 17:15
@dyc3
Copy link
Owner

dyc3 commented Jan 12, 2024

I took a look at it, and the problem is that the Stream wants owned values because it has to queue them internally before they get flushed to IO. I don't think this is feasible for us right now, so we can drop this task. Sorry about that.

@Victor-M-Giraldo
Copy link
Contributor Author

No problem. Do you think you could elaborate a little on what you mean just for my own understanding?

From what I understand stream can't take a reference to a variable. It must have ownership of msg but what does this have to do with Arc and what we were trying to do?

Thanks.

@dyc3
Copy link
Owner

dyc3 commented Jan 12, 2024

We get Arc<SocketMessage> from the channel, but we need to turn it into a Message (from the tungstenite crate) in order to call send. This is impossible to do without cloning the inner value of the Arc, which is what we are trying to avoid, or using unsafe code, which we also want to avoid.

@dyc3 dyc3 closed this Jan 12, 2024
@Victor-M-Giraldo Victor-M-Giraldo deleted the use-arc-for-broadcast-channels branch January 12, 2024 21:43
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.

Use Arc for room broadcast channels
2 participants