Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Fix 100% CPU usage by removing busy loop#2

Open
mrnugget wants to merge 3 commits intoDazWilkin:masterfrom
mrnugget:no-busy-loop
Open

Fix 100% CPU usage by removing busy loop#2
mrnugget wants to merge 3 commits intoDazWilkin:masterfrom
mrnugget:no-busy-loop

Conversation

@mrnugget
Copy link
Copy Markdown

@mrnugget mrnugget commented Jun 10, 2021

The previous loop was pinning a CPU completely. CPU usage was 100% of a single core.

With this loop though, the Go scheduler knows not to run it all the time. There are a ton of other ways to not have a busy loop, but this seems easiest.

@mrnugget
Copy link
Copy Markdown
Author

Update: it seems like this might break something, because values are not being published anymore. I'll take a look.

@mrnugget
Copy link
Copy Markdown
Author

Using the waitgroup, as in the f8d289d, fixes it and now there's barely any CPU usage.

// Loop forever while notification handler respond
wg := sync.WaitGroup{}
wg.Add(1)
for {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Now loop is redundant

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants