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

AudioFile.Read(): CPU usage unnecessarily @ 100 % #30

Open
joonas-fi opened this issue Apr 18, 2022 · 0 comments
Open

AudioFile.Read(): CPU usage unnecessarily @ 100 % #30

joonas-fi opened this issue Apr 18, 2022 · 0 comments

Comments

@joonas-fi
Copy link

a.requestChunk(chunkIdx)

When chunk hasn't arrived from server yet, the consumer code that is calling Read() will get 0-byte successful reads at rapid pace, until server responds. This means that the consumer is calling the read as fast as it can, millions of times a second, manifesting in 100 % CPU usage. After I inserted a 100 ms sleep in after the line I quoted, CPU usage is back to normal.

This behaviour is discouraged by the Reader interface:

Implementations of Read are discouraged from returning a zero byte count with a nil error

Source

It doesn't say it directly, but it means that Read() is expected to block until it has data to return.

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

No branches or pull requests

1 participant