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

DEV-376 new stressng format #30

Merged
merged 6 commits into from
Sep 26, 2024
Merged

DEV-376 new stressng format #30

merged 6 commits into from
Sep 26, 2024

Conversation

daroczig
Copy link
Member

@daroczig daroczig commented Sep 26, 2024

Overview

Required checks before merge

  • Branch is based on and up-to-date with main
  • PR has a clear title and/or brief description
  • PR builders passed
  • No red flags from coderabbit.ai
  • New features, bugfixes etc are tracked in CHANGELOG.md
  • Package version bumped in pyproject.toml
  • add_vendor.md is up-to-date
  • Alembic migrations are provided (or not needed)
    • Tested on SQLite
    • Tested on PostgreSQL
  • sc-crawler pull was tested on all vendors and records
  • Human approval

Summary by CodeRabbit

  • New Features

    • Introduced new benchmarks for measuring CPU performance: "stress-ng div16," "stress-ng div16 single-core," and "stress-ng div16 multi-core."
    • Enhanced server benchmark inspections with improved data handling and error logging.
  • Deprecations

    • Marked the previous "stress-ng CPU all" benchmark as deprecated in favor of the new benchmarks.
  • Bug Fixes

    • Improved error handling for reading benchmark data from files.

Copy link

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes involve modifications to the inspect_server_benchmarks function in src/sc_crawler/inspector.py to enhance server benchmark inspections, particularly for the "stress_ng" framework. Additionally, the _geekbenchmark function in src/sc_crawler/lookup.py is updated to deprecate an existing benchmark and introduce new benchmarks focused on CPU stress testing using the "div16" method.

Changes

File Change Summary
src/sc_crawler/inspector.py Modified inspect_server_benchmarks to add logic for handling "stress_ng" framework inspections, including error logging and structured data appending.
src/sc_crawler/lookup.py Updated _geekbenchmark to deprecate "stress-ng CPU all" and added new benchmarks for "stress-ng div16" configurations.

Assessment against linked issues

Objective Addressed Explanation
Handle stressng output redesign (DEV-376)

Possibly related PRs

Poem

In the code where benchmarks play,
A rabbit hops and cheers today!
With stress-ng now in the fray,
New metrics bloom, hooray, hooray!
For every core, both one and many,
Performance shines, our work's not any! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5b1a530 and a61ddf2.

📒 Files selected for processing (1)
  • src/sc_crawler/inspector.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/sc_crawler/inspector.py

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

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

🧹 Outside diff range and nitpick comments (5)
src/sc_crawler/lookup.py (4)

Line range hint 270-278: Approve deprecation notice and suggest CHANGELOG update

The addition of the deprecation notice for the "stress-ng CPU all" benchmark in favor of the new "stress_ng:div16" benchmark is appropriate and aligns with the PR objectives.

Please ensure that this deprecation is mentioned in the CHANGELOG.md file to keep users informed about this upcoming change.


279-290: Approve new div16 benchmark and suggest minor improvement

The addition of the "stress_ng:div16" benchmark is well-structured and provides a more specific measurement compared to the deprecated "CPU all" benchmark. This aligns with the PR objectives to implement a new format for stress-ng output handling.

Consider adding a brief explanation of what the "div16" method does in the description to provide more context for users unfamiliar with stress-ng internals.


291-301: Approve single-core benchmark and suggest clarification

The addition of the "stress_ng:best1" benchmark for single-core stress testing is a valuable addition, providing more granular performance data.

Consider clarifying in the description why this benchmark is named "best1". Is it because it measures the best performance of a single core? This would help users better understand the benchmark's purpose.


Missing Deprecation Notice for stress_ng:cpu_all

The deprecation notice for stress_ng:cpu_all is missing in src/sc_crawler/lookup.py. Additionally, there is still a reference to stress_ng:cpu_all in src/sc_crawler/inspector.py, which needs to be addressed to fully deprecate this benchmark.

  • src/sc_crawler/lookup.py: Add a deprecation message for stress_ng:cpu_all in the relevant section.
  • src/sc_crawler/inspector.py: Remove or update the comment referencing the deprecated stress_ng:cpu_all benchmark.
🔗 Analysis chain

Line range hint 270-312: Summary: New stress-ng benchmarks align with PR objectives

The changes to the stress-ng benchmarks in this file successfully implement a new format for handling the output of the stress-ng tool, as outlined in the PR objectives. The new benchmarks (div16, best1, and bestn) provide more specific and granular measurements compared to the deprecated "CPU all" benchmark, enhancing the overall benchmarking capabilities.

These changes align well with the goal of eliminating the need for a fallback mechanism and waiting until the new task has been successfully executed on all servers, as mentioned in the linked issue DEV-376.

To ensure these changes are properly reflected in the codebase, please run the following script:

This script will help verify the implementation of the new benchmarks and identify any other files that might need updates due to the deprecation of the "stress_ng:cpu_all" benchmark.


To resolve the issue with the rg command not recognizing the python file type, please run the following updated script:

This updated script removes the --type python flag and instead targets Python files by their .py extension. This should prevent the "unrecognized file type" error and allow for accurate searching within the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of new stress-ng benchmarks and the deprecation notice.

# Test 1: Check for the deprecation notice in the stress_ng:cpu_all benchmark
echo "Checking for deprecation notice:"
rg --type python 'stress_ng:cpu_all.*to be deprecated in favor of stress_ng:div16' src/sc_crawler/lookup.py

# Test 2: Verify the presence of new stress-ng benchmarks
echo "Checking for new stress-ng benchmarks:"
rg --type python 'benchmark_id="stress_ng:(div16|best1|bestn)"' src/sc_crawler/lookup.py

# Test 3: Check for updates in other files that might be affected by these changes
echo "Checking for potential updates needed in other files:"
rg --type python 'stress_ng:cpu_all' -g '!src/sc_crawler/lookup.py'

Length of output: 640


Script:

# 
#!/bin/bash
# Description: Verify the implementation of new stress-ng benchmarks and the deprecation notice.

# Test 1: Check for the deprecation notice in the stress_ng:cpu_all benchmark
echo "Checking for deprecation notice:"
rg 'stress_ng:cpu_all.*to be deprecated in favor of stress_ng:div16' src/sc_crawler/lookup.py

# Test 2: Verify the presence of new stress-ng benchmarks
echo "Checking for new stress-ng benchmarks:"
rg 'benchmark_id="stress_ng:(div16|best1|bestn)"' src/sc_crawler/lookup.py

# Test 3: Check for updates in other files that might be affected by these changes
echo "Checking for potential updates needed in other files:"
rg 'stress_ng:cpu_all' --glob '!src/sc_crawler/lookup.py' --type py

Length of output: 757

src/sc_crawler/inspector.py (1)

290-290: Reminder to address the deprecation TODO

There is a # TODO deprecate comment at line 290 indicating the intention to deprecate this section of the code. Please ensure that a deprecation plan is in place and that any necessary steps are documented or implemented.

Would you like assistance in drafting a deprecation plan or updating the code to reflect the deprecation?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1ae3a0a and 5b1a530.

📒 Files selected for processing (2)
  • src/sc_crawler/inspector.py (2 hunks)
  • src/sc_crawler/lookup.py (2 hunks)
🧰 Additional context used
🪛 Ruff
src/sc_crawler/inspector.py

313-313: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

🪛 GitHub Check: build
src/sc_crawler/inspector.py

[failure] 313-313: Ruff (F841)
src/sc_crawler/inspector.py:313:25: F841 Local variable e is assigned to but never used

Comment on lines +302 to +312
Benchmark(
benchmark_id="stress_ng:bestn",
name="stress-ng div16 multi-core",
description="Stress the CPU with the div16 method of stress-ng using a varying number of vCPU cores, and count the measured maximum total bogo operations per second based on wall clock run time.",
framework="stress_ng",
measurement="bestn",
config_fields={
"framework_version": "Version number of stress-ng.",
},
unit="bogo ops/s (real time)",
),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Approve multi-core benchmark and address missing parameter

The addition of the "stress_ng:bestn" benchmark for multi-core stress testing is valuable, complementing the single-core benchmark and providing a comprehensive view of CPU performance.

The description mentions "using a varying number of vCPU cores", but the config_fields don't include a "cores" parameter. This inconsistency should be addressed. Consider adding a "cores" parameter to the config_fields or clarify in the description how the number of cores is determined.

Comment on lines 313 to 342
except Exception as e:
# backfill with newer method - can be dropped once we deprecate stress_ng:cpu_all
try:
records = []
with open(
_server_framework_stdout_path(server, "stressngfull"), newline=""
) as f:
rows = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
for row in rows:
records.append(row)
for i in [0, len(records) - 1]:
stressng_version = _server_framework_meta(server, "stressngfull")[
"version"
]
benchmarks.append(
{
**_benchmark_metafields(
server,
framework="stressngfull",
benchmark_id=":".join([framework, "cpu_all"]),
),
"config": {
"cores": records[i][0],
"framework_version": stressng_version,
},
"score": records[i][1],
}
)
except Exception as e:
_log_cannot_load_benchmarks(server, framework, e, True)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor nested try-except blocks and narrow exception handling

The nested try-except blocks starting at line 313 can reduce code readability and make debugging more difficult. Additionally, catching the broad Exception class may mask unexpected errors.

Consider refactoring the exception handling to improve readability and robustness:

  • Narrow down the exceptions to catch specific errors (e.g., FileNotFoundError, IOError).
  • Flatten the nested try-except blocks to simplify the flow.

Here's a refactored version of the code:

        # TODO deprecate
        cores_per_path = {"stressng": server.vcpus, "stressngsinglecore": 1}
        for cores_path in cores_per_path.keys():
            try:
                stressng_version = _server_framework_meta(server, cores_path)["version"]
                line = _extract_line_from_file(
                    _server_framework_stderr_path(server, cores_path),
                    "bogo-ops-per-second-real-time",
                )
                benchmarks.append(
                    {
                        **_benchmark_metafields(
                            server,
                            framework=cores_path,
                            benchmark_id=":".join([framework, "cpu_all"]),
                        ),
                        "config": {
                            "cores": cores_per_path[cores_path],
                            "framework_version": stressng_version,
                        },
                        "score": float(line.split(": ")[1]),
                    }
                )
            except (FileNotFoundError, KeyError, ValueError) as e:
                _log_cannot_load_benchmarks(server, framework, e, True)
                # Attempt to backfill with newer method
                try:
                    records = []
                    with open(
                        _server_framework_stdout_path(server, "stressngfull"), newline=""
                    ) as f:
                        rows = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
                        for row in rows:
                            records.append(row)
                    for i in [0, len(records) - 1]:
                        stressng_version = _server_framework_meta(server, "stressngfull")[
                            "version"
                        ]
                        benchmarks.append(
                            {
                                **_benchmark_metafields(
                                    server,
                                    framework="stressngfull",
                                    benchmark_id=":".join([framework, "cpu_all"]),
                                ),
                                "config": {
                                    "cores": records[i][0],
                                    "framework_version": stressng_version,
                                },
                                "score": records[i][1],
                            }
                        )
                except Exception as e:
                    _log_cannot_load_benchmarks(server, framework, e, True)

This refactoring:

  • Moves the try-except inside the loop for clearer logic.
  • Catches specific exceptions to prevent masking other errors.
  • Utilizes logging to handle exceptions appropriately.
🧰 Tools
🪛 Ruff

313-313: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

🪛 GitHub Check: build

[failure] 313-313: Ruff (F841)
src/sc_crawler/inspector.py:313:25: F841 Local variable e is assigned to but never used

@@ -309,6 +310,78 @@
"score": float(line.split(": ")[1]),
}
)
except Exception as e:
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused variable e in exception handler

The variable e is assigned but never used in the except block at line 313. This can be cleaned up by removing the variable if it's not needed.

Apply this diff to remove the unused variable:

-        except Exception as e:
+        except Exception:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except Exception as e:
except Exception:
🧰 Tools
🪛 Ruff

313-313: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

🪛 GitHub Check: build

[failure] 313-313: Ruff (F841)
src/sc_crawler/inspector.py:313:25: F841 Local variable e is assigned to but never used

@daroczig daroczig merged commit 40f315d into main Sep 26, 2024
2 checks passed
@daroczig daroczig deleted the DEV-376 branch September 26, 2024 14:44
@coderabbitai coderabbitai bot mentioned this pull request Nov 9, 2024
12 tasks
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.

1 participant