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

code-standards(submit loop): small refactor to submit loop to move timer to submitter thread #1014

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

danwt
Copy link
Contributor

@danwt danwt commented Aug 12, 2024

PR Standards

Opening a pull request should be able to meet the following requirements

--

PR naming convention: https://hackmd.io/@nZpxHZ0CT7O5ngTp0TP9mg/HJP_jrm7A


Close #XXX

<-- Briefly describe the content of this pull request -->

For Author:

  • Targeted PR against correct branch
  • included the correct type prefix in the PR title
  • Linked to Github issue with discussion and accepted design
  • Targets only one github issue
  • Wrote unit and integration tests
  • All CI checks have passed
  • Added relevant godoc comments

For Reviewer:

  • confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • confirmed all author checklist items have been addressed

After reviewer approval:

  • In case targets main branch, PR should be squashed and merged.
  • In case PR targets a release branch, PR should be rebased.

Summary by CodeRabbit

  • New Features

    • Improved submission handling logic to enhance responsiveness and robustness.
  • Bug Fixes

    • Adjusted timers and triggers to reduce the risk of deadlocks and missed submissions.
  • Tests

    • Enhanced test configurations to improve stability and adaptability across different environments.

@danwt danwt requested a review from a team as a code owner August 12, 2024 16:06
Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

The recent changes enhance the submission logic in the SubmitLoopInner function by eliminating the ticker from the goroutine monitoring pending bytes. This adjustment reduces the risk of deadlocks and improves clarity. The testing framework is also refined, increasing execution time limits and decreasing concurrency levels to boost stability. These modifications aim to bolster both the robustness of the submission process and the adaptability of tests across various environments.

Changes

Files Change Summary
block/submit.go Removed ticker from the first goroutine to avoid deadlocks; clarified comments on managing back-pressure; retained and reset ticker in the second goroutine for timing control.
block/submit_loop_test.go Adjusted absoluteMax to twice args.maxTime for better test execution timing; reduced nParallel from 100 to 50 for improved stability during tests.

Poem

🐇 In the code where bytes do flow,
A rabbit hops, with logic aglow.
No more tickers, clean and bright,
Submissions dance, both swift and light.
Tests now run with grace anew,
A smoother path for all to view! 🌟


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.

@danwt
Copy link
Contributor Author

danwt commented Aug 12, 2024

partially to address some complaints #1011 (comment)

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 f3e69a3 and 17cd13c.

Files selected for processing (2)
  • block/submit.go (4 hunks)
  • block/submit_loop_test.go (3 hunks)
Additional comments not posted (5)
block/submit_loop_test.go (2)

118-118: Verify the impact of reducing nParallel.

The reduction from 100 to 50 in nParallel may improve test stability. Ensure this change doesn't affect the test coverage or objectives.

Also applies to: 139-139

Verification successful

Reduction of nParallel from 100 to 50 is likely for stability improvement.

The change in nParallel from 100 to 50 appears to be aimed at improving test stability by reducing resource contention without affecting the overall test objectives. The test still adequately covers concurrency behavior with this adjustment.

  • Ensure that the test objectives focus on concurrency behavior rather than maximum load to confirm this change is appropriate.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of reducing `nParallel` on test coverage and objectives.

# Test: Search for the usage of `nParallel` in the test file. Expect: No adverse impact on test coverage.
rg --type go 'nParallel' -A 5

Length of output: 1636


102-102: Verify the rationale for increasing absoluteMax.

The change from 1.5 to 2 times args.maxTime increases the allowed time for test execution, which may help accommodate performance variations. Ensure this change aligns with the test objectives and doesn't mask performance issues.

Verification successful

Change to absoluteMax Verified

The increase in absoluteMax from 1.5 to 2 times args.maxTime provides additional leeway for test execution time, which can be beneficial in accommodating performance variations across different environments. This change aligns with the test objectives and does not appear to mask performance issues.

  • Usage of absoluteMax is consistent with ensuring sufficient leeway for execution time and produced bytes.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `absoluteMax` in tests to ensure it aligns with the test objectives.

# Test: Search for the usage of `absoluteMax` in the test file. Expect: Alignment with test objectives.
rg --type go 'absoluteMax' -A 5

Length of output: 1226

block/submit.go (3)

55-56: Improved documentation enhances clarity.

The clearer comments on the roles of the goroutines enhance code clarity and maintainability. Ensure comments accurately reflect the logic.

Also applies to: 80-82


80-82: LGTM! Verify ticker usage alignment.

The clarified purpose and reset enhance submission timing control. Ensure the ticker usage aligns with the intended submission logic.

Also applies to: 87-87, 91-93, 113-113

Verification successful

Ticker usage aligns with submission logic.

The ticker in block/submit.go is used to periodically trigger actions and is reset after batch submissions, consistent with the intended timing control. This aligns with the clarified purpose and enhances submission timing.

  • block/submit.go: Ticker usage within the select statement and reset after submission confirms alignment.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the alignment of ticker usage with the intended submission logic.

# Test: Search for the ticker usage in the second goroutine. Expect: Alignment with submission logic.
rg --type go 'ticker' -A 5

Length of output: 3874


55-56: LGTM! Verify back-pressure management.

The removal of the ticker simplifies control flow and reduces potential deadlocks. Ensure the logic effectively manages back-pressure without introducing new issues.

Verification successful

Back-pressure management logic appears correct.

The code effectively manages back-pressure by blocking when too much data is pending. Ensure this logic is correctly integrated without introducing new issues.

  • Code Location: block/submit.go
    • Condition: if maxBatchSkew*maxBatchBytes < pendingBytes.Load()
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the effectiveness of back-pressure management in the first goroutine.

# Test: Search for the logic managing back-pressure. Expect: No new issues introduced.
rg --type go 'back-pressure' -A 5

Length of output: 488

timeLastSubmission := time.Now()
ticker := time.NewTicker(maxBatchTime / 10) // interval does not need to match max batch time since we keep track anyway, it's just to wakeup
Copy link
Contributor

Choose a reason for hiding this comment

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

why submitter needs to just to wakeup?
u should move the maxDataNotExceeded and lastSubmissionIsRecent checks to trigger

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why 'should' I?
You need to actually argue and prove it works

Copy link
Contributor Author

@danwt danwt Aug 13, 2024

Choose a reason for hiding this comment

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

anyways happy to merge this? because it's an improvement regardless

@mtsitrin mtsitrin merged commit d31bcf1 into main Aug 13, 2024
7 checks passed
@mtsitrin mtsitrin deleted the danwt/submission-cleanup branch August 13, 2024 09:14
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