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

(DAL) Pooling broadcast #2246

Merged
merged 4 commits into from
Aug 28, 2024
Merged

(DAL) Pooling broadcast #2246

merged 4 commits into from
Aug 28, 2024

Conversation

nick-bisonai
Copy link
Collaborator

Description

Goroutine pooling on broadcasting data

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Aug 28, 2024
@nick-bisonai nick-bisonai requested a review from a team as a code owner August 28, 2024 06:16
Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Walkthrough

Walkthrough

The changes introduce a worker pool to the Hub struct, enhancing its ability to manage concurrent tasks. A new field for the worker pool is added, and modifications to the NewHub constructor and Start method allow for efficient task handling. The castSubmissionData method is updated to utilize the worker pool for job management, replacing manual synchronization with a streamlined approach. Additionally, a method within the Pool struct is renamed for clarity.

Changes

Files Change Summary
node/pkg/dal/hub/hub.go - Added pool field to Hub struct for worker pool management.
- Introduced constant WORKER_COUNT set to 100.
- Updated NewHub to initialize the pool.
- Modified Start to run the worker pool.
- Changed castSubmissionData to use h.pool.AddJob.
node/pkg/utils/pool/pool.go - Renamed method worker to runWorker in Pool struct, updating its declaration and usage in the Run method.

Sequence Diagram(s)

sequenceDiagram
    participant H as Hub
    participant P as Pool
    participant C as Collector

    H->>H: NewHub(configs)
    H->>P: Initialize pool
    H->>C: Start(ctx)
    C->>P: Run(ctx)
    H->>P: AddJob(task)
    P->>P: runWorker(ctx)
Loading

🐰 In the hub where tasks align,
With workers ready, all in line.
A pool of joy, swift and bright,
Concurrency dances, a wondrous sight!
The code now flows, smooth as a stream,
Hopping along, we chase the dream! 🌟


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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.

@nick-bisonai nick-bisonai linked an issue Aug 28, 2024 that may be closed by this pull request
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e714bf2 and b2f5f98.

Files selected for processing (2)
  • node/pkg/dal/hub/hub.go (4 hunks)
  • node/pkg/utils/pool/pool.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • node/pkg/utils/pool/pool.go
Additional comments not posted (5)
node/pkg/dal/hub/hub.go (5)

33-33: Approved structural change to Hub struct.

The addition of the pool field is crucial for managing worker goroutines efficiently.

The structural change is approved as it aligns with the PR objectives.


38-38: Verify the appropriateness of WORKER_COUNT.

The constant WORKER_COUNT is set to 20. It's important to ensure this number is optimized based on the expected load and system capabilities.

Consider providing benchmarks or rationale for choosing this specific count.


59-59: Approved changes in NewHub constructor.

Initializing the pool field within the constructor ensures that the Hub is ready to manage tasks using the worker pool.

The change is approved as it is crucial for the functionality of the pooling mechanism.


64-64: Approved changes in Start method.

The inclusion of h.pool.Run(ctx) is essential for activating the worker pool, allowing the Hub to handle tasks concurrently.

The change is approved as it directly supports the PR objectives of enhancing concurrency management.


165-170: Approved changes in castSubmissionData method.

Utilizing the worker pool in castSubmissionData simplifies concurrency management and is likely to improve performance. However, consider adding error handling for job submission failures.

The changes are approved, but it's recommended to enhance robustness by handling potential job submission failures.

}
}

func (p *Pool) worker(ctx context.Context) {
func (p *Pool) work(ctx context.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

worker in this context refers to goroutines that run the actual task/job/work. And seems like "In the context of a worker pool, the worker term is a widely accepted convention".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought function name should be verb rather than noun, since it does some action rather than just a property or a value. how do you think? if it is worker, at first sight I thought it should be some sort of struct or value

Copy link
Collaborator Author

@nick-bisonai nick-bisonai Aug 28, 2024

Choose a reason for hiding this comment

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

well it seems trivial and minor so I'm not insisting, either is good for me. I'll rollback if you mind

Copy link
Contributor

Choose a reason for hiding this comment

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

that's a valid point. But i found work a bit weird as well lol. So maybe runWorker? 😄

Copy link
Contributor

@Intizar-T Intizar-T left a comment

Choose a reason for hiding this comment

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

lgtm! left a suggestion 🙏

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2f5f98 and 6f8e22d.

Files selected for processing (1)
  • node/pkg/utils/pool/pool.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • node/pkg/utils/pool/pool.go

@nick-bisonai nick-bisonai merged commit 12378ae into master Aug 28, 2024
1 check passed
@nick-bisonai nick-bisonai deleted the feat/dal-broadcast-pooling branch August 28, 2024 08:19
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f8e22d and 193f658.

Files selected for processing (1)
  • node/pkg/dal/hub/hub.go (4 hunks)
Additional comments not posted (5)
node/pkg/dal/hub/hub.go (5)

33-33: Addition of pool field in Hub struct approved.

The new pool field is essential for the efficient management of goroutines, aligning well with the PR's objectives.

The addition of the pool field is approved.


38-38: Introduction of WORKER_COUNT constant approved.

Setting this constant provides a clear reference point for tuning the number of workers in the pool, which is beneficial for scalability and performance adjustments.

The introduction of the WORKER_COUNT constant is approved.


59-59: Initialization of pool in NewHub function approved.

Properly initializing the pool with pool.NewPool(WORKER_COUNT) ensures that each Hub instance can handle concurrent tasks efficiently.

The changes in the NewHub function are approved.


64-64: Starting the worker pool in Start function approved.

Calling h.pool.Run(ctx) at the beginning of the Start method ensures that the worker pool is operational and ready to handle tasks concurrently.

The changes in the Start function are approved.


165-170: Refactoring castSubmissionData to use worker pool approved.

Replacing manual synchronization with h.pool.AddJob simplifies the concurrency management and leverages the worker pool efficiently.

The changes in the castSubmissionData function are approved.

nick-bisonai added a commit that referenced this pull request Aug 28, 2024
nick-bisonai added a commit that referenced this pull request Aug 28, 2024
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.

Optimize broadcast logic in Hub for better performance
2 participants