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

load_test: update the Queue class provider to work well on MacOS #92

Merged
merged 2 commits into from
Mar 3, 2025

Conversation

kpouget
Copy link
Contributor

@kpouget kpouget commented Feb 14, 2025

see https://stackoverflow.com/questions/65609529/python-multiprocessing-queue-notimplementederror-macos

Summary by CodeRabbit

  • Refactor
    • Improved internal handling of inter-process communication for more robust and reliable concurrent operations.

Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

The changes modify load_test.py to use a new multiprocessing manager for queue creation. Instead of the previous context-based queues (using mp_ctx.Queue()), the code now instantiates logger_q, stop_q, and dataset_q with mp_mgr.Queue(). This change enhances inter-process communication by centralizing queue management with a multiprocessing manager while maintaining the original error handling and overall control flow.

Changes

File Changes
load_test.py Introduced mp_mgr via mp.Manager(). Updated queue declarations for logger_q, stop_q, and dataset_q from mp_ctx.Queue() to mp_mgr.Queue().

Sequence Diagram(s)

sequenceDiagram
    participant Main as Main Script
    participant Manager as MP Manager
    participant Worker as Worker Process

    Main->>Manager: Instantiate mp_mgr via mp.Manager()
    Main->>Manager: Create logger_q, stop_q, dataset_q using mp_mgr.Queue()
    Manager-->>Main: Return shared queues
    loop Inter-process communication
        Worker->>Manager: Request queue operations (log, stop, dataset tasks)
        Manager-->>Worker: Process queue actions
    end
Loading

Poem

In a code field so vast and new,
I hopped along with queues that flew.
mp_mgr led the way so bright,
Guiding messages day and night.
With hops and bytes in joyful cheer,
This rabbit sings: "Our queues are here!"
🐇✨

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc906c1 and ad177df.

📒 Files selected for processing (1)
  • load_test.py (2 hunks)
🔇 Additional comments (5)
load_test.py (5)

1-2: Good addition of the shebang line.

The shebang line makes the script directly executable on Unix-like systems including MacOS, which aligns with the goal of improving MacOS compatibility.


122-123: Well-implemented manager for MacOS compatibility.

Using a manager object is a good approach to solve the NotImplementedError that can occur with Python multiprocessing Queue on MacOS. The Manager provides a server process that manages shared objects like queues across processes, ensuring better compatibility.


124-124: Appropriate change to manager-based queue.

Changing from mp_ctx.Queue() to mp_mgr.Queue() for the logger queue addresses the MacOS compatibility issue.


128-129: Consistent implementation of manager-based queues.

Good job consistently applying the manager-based queue approach to all queues in the code.


154-154: Consider using the manager for process creation.

Currently, processes are created using mp_ctx in the create_procs function, while queues use mp_mgr. For consistency, you might want to consider using the manager for process creation as well.

This comment aligns with a previous review suggestion that mentioned: "I think if we are using the manager class instead of context-based multi-processing, we should also use it to spin new processes (line #152). Have you tried using mp_mgr for the create_procs?"

Run the following to verify if this would work in your environment:

#!/bin/bash
# Verify if Manager can be used for process creation on MacOS
python3 -c "
import multiprocessing as mp
import platform

print(f'Testing on platform: {platform.system()}')

# Test if manager can create processes
mp_ctx = mp.get_context('spawn')
mp_mgr = mp_ctx.Manager()

try:
    # Try to create a process through the manager
    def test_func():
        print('Process created successfully')
    
    # See if Manager has a Process method like mp_ctx does
    if hasattr(mp_mgr, 'Process'):
        p = mp_mgr.Process(target=test_func)
        print('Manager has Process method')
    else:
        print('Manager does not have Process method, must continue using mp_ctx for process creation')
        # This is the current approach in the code
        p = mp_ctx.Process(target=test_func)
    
    p.start()
    p.join()
    
except Exception as e:
    print(f'Error: {e}')
"

[skip_cloning]

✨ Finishing Touches
  • 📝 Generate Docstrings

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 generate docstrings to generate docstrings for this 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: 0

🧹 Nitpick comments (1)
load_test.py (1)

126-127: LGTM! Consider documenting the MacOS compatibility fix.

The migration to manager-based queues is well-implemented. Consider adding a comment explaining why manager-based queues are used to help future maintainers understand the MacOS compatibility consideration.

+    # Use manager-based queues for better MacOS compatibility
     stop_q = mp_mgr.Queue(1)
     dataset_q = mp_mgr.Queue()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 23db634 and cc906c1.

📒 Files selected for processing (1)
  • load_test.py (1 hunks)
🔇 Additional comments (2)
load_test.py (2)

119-119: LGTM! Good solution for MacOS compatibility.

Using a multiprocessing Manager is a robust solution for handling shared queues across processes on MacOS, where the default Queue implementation can sometimes raise NotImplementedError.


122-122: LGTM! Consistent queue management.

The logger queue is correctly migrated to use the multiprocessing manager, maintaining consistent queue management across the application.

Copy link
Member

@sjmonson sjmonson left a comment

Choose a reason for hiding this comment

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

LGTM

load_test.py Outdated
@@ -116,13 +116,15 @@ def main(args):
"""Load test CLI entrypoint."""
args = utils.parse_args(args)

mp_mgr = mp.Manager()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if we are using the manager class instead of context-based multi-processing, we should also use it to spin new processes (line #152). Have you tried using mp_mgr for the create_procs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch Nikhil. I followed the other suggestion.

@kpouget
Copy link
Contributor Author

kpouget commented Feb 26, 2025

I updated the code to follow @npalaska's suggestion, and I added a shebang header to make it easier to launch the load test manually.

Tested on MacOS.

@kpouget
Copy link
Contributor Author

kpouget commented Mar 3, 2025

@npalaska @sjmonson @dagrayvid any other feedback? good to merge?

@dagrayvid
Copy link
Collaborator

lgtm!

@dagrayvid dagrayvid merged commit 1f5fc43 into openshift-psap:main Mar 3, 2025
2 checks passed
@kpouget
Copy link
Contributor Author

kpouget commented Mar 3, 2025

great, thanks 🎉

kpouget added a commit to kpouget/topsail that referenced this pull request Mar 3, 2025
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.

4 participants