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

Refactor reportAllRunningContainers to use worker goroutines #25

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

thang14
Copy link
Contributor

@thang14 thang14 commented Feb 25, 2025

This pull request introduces several changes to the core/apps/app_report.go file to improve the efficiency and reliability of reporting on running containers. The key changes include the addition of concurrency for processing containers, the removal of the ticker, and the introduction of a new helper function to process individual containers.

Concurrency improvements:

  • Added runtime and sync packages to support concurrent processing of containers.
  • Implemented a worker pool using sync.WaitGroup and runtime.NumCPU() to process containers concurrently.

Refactoring and code simplification:

  • Removed the time.Ticker and replaced it with a time.Sleep loop to simplify the reporting loop.
  • Extracted container processing logic into a new helper function processReportContainer to improve code readability and maintainability.

Logging and error handling:

  • Added logging to report the number of running containers found.
  • Improved error handling by ensuring the function returns immediately upon encountering an error, rather than using continue.

- Refactor `reportAllRunningContainers` to use worker goroutines for processing containers.
- Improve concurrency and efficiency by utilizing multiple CPU cores.
@thang14 thang14 merged commit 6422d89 into main Feb 25, 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.

1 participant