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

Fix busy-waiting loops #2977

Open
iluwatar opened this issue Jun 1, 2024 · 4 comments
Open

Fix busy-waiting loops #2977

iluwatar opened this issue Jun 1, 2024 · 4 comments
Assignees
Labels
epic: code quality info: good first issue status: stale issues and pull requests that have not had recent interaction

Comments

@iluwatar
Copy link
Owner

iluwatar commented Jun 1, 2024

Description

Busy-waiting, or spinning, is a technique where a process repeatedly checks to see if a condition is true, such as whether keyboard input or a lock is available. While it might seem like a good idea, it has several significant drawbacks:

  1. CPU Usage: Busy-waiting can consume a lot of CPU time. While a process is busy-waiting, it keeps the CPU busy. This can prevent other processes from running and can lead to high CPU usage, especially if the condition being checked doesn't become true for a long time.
  2. Performance: Busy-waiting can lead to performance issues. If a process is busy-waiting, it's not doing any useful work. This can slow down the overall performance of your application.
  3. Responsiveness: Busy-waiting can make your application less responsive. If a process is busy-waiting, it might not be able to respond to user input or other events in a timely manner.
  4. Power Consumption: Busy-waiting can lead to increased power consumption, especially on battery-powered devices. This is because the CPU is kept busy and is not allowed to enter a low-power state.

Instead of busy-waiting, it's generally better to use some form of event-driven programming or blocking. This allows your process to sleep until the condition it's waiting for becomes true, which can save CPU time, improve performance, and make your application more responsive.

Busy-waiting loops are at least in these locations:

  1. Server Session / App.java
  2. Twin / BallThread.java
  3. Log Aggregation / LogAggregator.java
  4. Commander / Retry.java
  5. Retry / Retry.java
  6. Retry / RetryExponentialBackoff.java
  7. Queue-Based Load Leveling / ServiceExecutor.java

Acceptance Criteria

  • Busy-waiting loops refactored
  • README.md of the affected patterns revised as needed
@TATIKONDAVENKATESH
Copy link

i am new here, i want to contribute to this project

@Mehdi-17
Copy link

Mehdi-17 commented Jul 2, 2024

Hello, i'm available to work on it

@Mehdi-17
Copy link

Thanks, I've just started working on this.

Copy link

stale bot commented Sep 11, 2024

This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale issues and pull requests that have not had recent interaction label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic: code quality info: good first issue status: stale issues and pull requests that have not had recent interaction
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants