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

Problem: single validator benchmark can't run natively #1649

Merged
merged 5 commits into from
Oct 18, 2024

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Oct 18, 2024

single validator benchmark should be runnable locally, since there are no port issues

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Summary by CodeRabbit

  • New Features

    • Introduced a new command for manual load generation in the CLI.
    • Added an abort option in the PrepareProposal process.
  • Improvements

    • Enhanced transaction generation and retry mechanisms for load generators.
    • Updated local RPC connection settings for better maintainability.
    • Improved error handling in the CLI commands.
  • Bug Fixes

    • Resolved issues related to validator benchmarks and transaction processing.
  • Documentation

    • Updated the CHANGELOG to reflect recent changes and fixes across multiple releases.

single validator benchmark should be runnable locally, since there are no
port issues

temp
CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: yihuang <[email protected]>
@yihuang yihuang marked this pull request as ready for review October 18, 2024 03:45
@yihuang yihuang requested a review from a team as a code owner October 18, 2024 03:45
@yihuang yihuang requested review from mmsqe and JayT106 and removed request for a team October 18, 2024 03:45
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request includes updates to the CHANGELOG.md file to document bug fixes and enhancements across multiple releases, including improvements in transaction generation and handling. The stateless.py file introduces a new command for manual load generation and refactors transaction management logic. The transaction.py file updates connection settings to use constants instead of hardcoded values, while utils.py modifies RPC connection URLs for better maintainability. Overall, these changes aim to enhance functionality and stability in the software.

Changes

File Path Change Summary
CHANGELOG.md Added a section for bug fixes under "UNRELEASED"; documented various updates and fixes across releases.
testground/benchmark/benchmark/stateless.py Added generate_load command; updated run command for type safety; refactored transaction handling into prepare_txs.
testground/benchmark/benchmark/transaction.py Updated import for LOCAL_JSON_RPC; replaced hardcoded values with constants, specifically CONNECTION_POOL_SIZE.
testground/benchmark/benchmark/utils.py Updated LOCAL_RPC URL; added LOCAL_JSON_RPC variable for maintainability in RPC connections.

Possibly related PRs

Suggested reviewers

  • JayT106
  • leejw51crypto

Poem

🐇 In the code where bunnies play,
Enhancements hop in bright array.
With transactions swift and neat,
Load generation can't be beat!
Changelog sings of fixes grand,
A stable world at our command! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 864c777 and a7f93f8.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

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>, 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.

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.

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.64%. Comparing base (b08f6d6) to head (a7f93f8).
Report is 1 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (b08f6d6) and HEAD (a7f93f8). Click for more details.

HEAD has 12 uploads less than BASE
Flag BASE (b08f6d6) HEAD (a7f93f8)
integration_tests 20 10
2 0
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1649       +/-   ##
===========================================
- Coverage   34.94%   16.64%   -18.30%     
===========================================
  Files         123       72       -51     
  Lines       11803     6212     -5591     
===========================================
- Hits         4124     1034     -3090     
+ Misses       7265     5055     -2210     
+ Partials      414      123      -291     

see 69 files with indirect coverage changes

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: 1

🧹 Outside diff range and nitpick comments (8)
testground/benchmark/benchmark/transaction.py (2)

14-14: Approved changes with a suggestion for improvement

The changes improve code organization and maintainability:

  1. Importing LOCAL_JSON_RPC from .utils centralizes configuration.
  2. Introducing CONNECTION_POOL_SIZE as a constant improves readability and maintainability.

Consider adding a comment explaining the rationale behind the CONNECTION_POOL_SIZE value of 1024. This would help future maintainers understand if this value needs adjustment based on specific requirements or performance considerations.

Also applies to: 17-17


Line range hint 1-133: Overall impact of changes is positive with a suggestion for further improvement

The modifications in this file contribute to the PR objectives by:

  1. Centralizing configuration with the LOCAL_JSON_RPC import.
  2. Improving maintainability with the CONNECTION_POOL_SIZE constant.
  3. Enhancing configurability of connection settings.

These changes should help in resolving port conflicts and enabling the single validator benchmark to run natively.

To further improve the code's flexibility, consider making CONNECTION_POOL_SIZE configurable through environment variables or a configuration file. This would allow for easier adjustment of the connection pool size without code changes, which could be beneficial for different testing scenarios or environments.

testground/benchmark/benchmark/utils.py (3)

16-16: LGTM. Consider using an environment variable for flexibility.

The change from 'localhost' to '127.0.0.1' is acceptable and may help avoid potential DNS resolution issues. However, to improve flexibility and ease of configuration across different environments, consider using an environment variable for the RPC URL.

Here's a suggested improvement:

import os

LOCAL_RPC = os.environ.get('LOCAL_RPC', "http://127.0.0.1:26657")

This allows easy overriding of the RPC URL without modifying the code.


17-17: LGTM. Consider using an environment variable for consistency.

The addition of LOCAL_JSON_RPC improves code maintainability by centralizing the JSON-RPC endpoint configuration. For consistency with the previous suggestion and to maintain flexibility across environments, consider using an environment variable for this URL as well.

Here's a suggested improvement:

import os

LOCAL_JSON_RPC = os.environ.get('LOCAL_JSON_RPC', "http://127.0.0.1:8545")

This allows easy overriding of the JSON-RPC URL without modifying the code and maintains consistency with the LOCAL_RPC variable.


Line range hint 1-190: Summary: Changes align well with PR objectives and improve maintainability.

The modifications in this file contribute effectively to the PR's goal of enabling the single validator benchmark to run natively without port conflicts. The centralization of RPC configurations improves maintainability and consistency across the codebase.

To further enhance flexibility and ease of configuration across different environments, consider implementing the suggested improvements using environment variables for both LOCAL_RPC and LOCAL_JSON_RPC.

Overall, these changes are well-implemented and support the PR objectives.

CHANGELOG.md (2)

5-7: Update the changelog entry as suggested in the previous review.

The current entry:

* (testground)[1649](https://github.com/crypto-org-chain/cronos/pull/1649) Fix running single validator benchmark locally.

Should be updated to:

* (testground)[#1649](https://github.com/crypto-org-chain/cronos/pull/1649) Fix running single validator benchmark locally.

This change adds a # before the pull request number, which is the standard format for GitHub issue/PR links.


Line range hint 1-1186: LGTM! Well-structured and informative changelog.

The changelog is well-organized and provides detailed information about each release. The categorization of changes into "State Machine Breaking", "Improvements", and "Bug Fixes" helps users quickly understand the impact of each release.

For consistency, consider adding dates to all release sections, not just some of them. This would help users understand the timeline of releases more clearly.

testground/benchmark/benchmark/stateless.py (1)

198-203: Log exceptions instead of passing silently

In the except OSError: block, the exception is silently ignored with a pass. Logging the exception can aid in debugging and provide valuable information if unexpected issues occur.

 except OSError as e:
     # Ignore if the file is not writable when running in bare metal
-    pass
+    print(f"Failed to create tarball: {e}")

Alternatively, consider using the logging module for more flexible logging.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 007077a and dc4b145.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • testground/benchmark/benchmark/stateless.py (6 hunks)
  • testground/benchmark/benchmark/transaction.py (2 hunks)
  • testground/benchmark/benchmark/utils.py (2 hunks)
🧰 Additional context used
🪛 GitHub Check: Lint python
testground/benchmark/benchmark/stateless.py

[failure] 234-234:
./testground/benchmark/benchmark/stateless.py:234:5: BLK100 Black would make changes.

🔇 Additional comments (4)
testground/benchmark/benchmark/transaction.py (1)

130-133: Approved changes in the send function

The modification to use CONNECTION_POOL_SIZE in the aiohttp.TCPConnector initialization improves code maintainability and consistency. This change aligns well with the goal of making the code more configurable and easier to maintain.

testground/benchmark/benchmark/utils.py (1)

97-97: LGTM. Good use of the new LOCAL_JSON_RPC variable.

This change improves code maintainability by using the centralized LOCAL_JSON_RPC configuration instead of a hardcoded URL. It's consistent with the earlier changes and supports the PR objective of enabling the single validator benchmark to run natively.

testground/benchmark/benchmark/stateless.py (2)

7-7: Importing the sys module is appropriate

The sys module is correctly imported to use sys.stdout later in the code.


234-236: Docstring formatting has been previously addressed

The formatting issue with the docstring for generate_load has been noted in prior review comments.

🧰 Tools
🪛 GitHub Check: Lint python

[failure] 234-234:
./testground/benchmark/benchmark/stateless.py:234:5: BLK100 Black would make changes.

@yihuang yihuang enabled auto-merge October 18, 2024 04:11
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: 1

🧹 Outside diff range and nitpick comments (3)
testground/benchmark/benchmark/stateless.py (3)

198-210: Approve: Improved error handling for output file creation

The addition of the try-except block for tar file creation enhances the robustness of the code, particularly when running in environments where file writing might fail. This is a good improvement.

A minor suggestion to consider:

  • You could log the error when the file is not writable to aid in debugging. For example:
except OSError as e:
    print(f"Warning: Unable to create output file: {e}", file=sys.stderr)

This would provide more information about why the file couldn't be created without interrupting the program's execution.


230-243: Approve: New generate_load command with suggestion for improved documentation

The addition of the generate_load command is a valuable feature for manually generating load on an existing node. The implementation looks solid, utilizing the prepare_txs function and providing informative output.

Suggestion for improvement:

  • Enhance the docstring to provide more details about the command's purpose, usage, and parameters. For example:
def generate_load(datadir: Path, global_seq: int):
    """
    Manually generate load for an existing node.

    This command prepares and sends transactions to an existing node,
    waits for a specified number of idle blocks, and then dumps block stats.

    Args:
        datadir (Path): Path to the data directory containing the config.json file.
        global_seq (int): Global sequence number for transaction generation.

    Usage:
        $ python stateless.py generate-load --datadir /path/to/data --global-seq 0
    """
    # ... (rest of the function remains the same)

This improved docstring would make the command's purpose and usage clearer to other developers or users of the script.


433-442: Approve: New prepare_txs function with suggestion for error handling

The addition of the prepare_txs function is a good improvement to the code structure. It encapsulates the logic for loading or generating transactions, making the code more modular and easier to maintain. The function is well-implemented and provides clear output about the transactions being prepared.

Suggestion for improvement:
Consider adding basic error handling to make the function more robust. For example:

def prepare_txs(cfg, datadir, global_seq):
    try:
        txs = transaction.load(datadir, global_seq)
        if txs:
            print("loaded", len(txs), "txs")
        else:
            print("generating", cfg["num_accounts"] * cfg["num_txs"], "txs")
            txs = transaction.gen(
                global_seq, cfg["num_accounts"], cfg["num_txs"], cfg["tx_type"]
            )
        return txs
    except Exception as e:
        print(f"Error preparing transactions: {e}", file=sys.stderr)
        return []

This addition would ensure that the function always returns a list of transactions, even if an error occurs during loading or generation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dc4b145 and 864c777.

📒 Files selected for processing (1)
  • testground/benchmark/benchmark/stateless.py (6 hunks)
🧰 Additional context used
🔇 Additional comments (2)
testground/benchmark/benchmark/stateless.py (2)

273-273: Approve: Refactored transaction preparation

The use of the prepare_txs function to prepare transactions in the do_run function is a good refactoring decision. This change:

  1. Centralizes the logic for transaction preparation, improving maintainability.
  2. Enhances code reusability, as the same function is used in both do_run and the new generate_load command.
  3. Makes the code more modular and easier to understand.

This refactoring aligns well with the DRY (Don't Repeat Yourself) principle and improves the overall structure of the code.


7-7: Approve: Addition of sys module import

The addition of the sys module import is appropriate and necessary for the new functionality in the generate_load function, where it's used to print block stats to stdout. This import is correctly placed at the beginning of the file with other standard library imports.

testground/benchmark/benchmark/stateless.py Show resolved Hide resolved
@yihuang yihuang added this pull request to the merge queue Oct 18, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Oct 18, 2024
@mmsqe mmsqe enabled auto-merge October 18, 2024 05:36
@mmsqe mmsqe added this pull request to the merge queue Oct 18, 2024
Merged via the queue into crypto-org-chain:main with commit 85ca58b Oct 18, 2024
42 of 43 checks passed
@yihuang yihuang deleted the fix-native-run branch October 18, 2024 06: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.

2 participants