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

CPU usage when idle #132

Closed
AlexanderPavlenko opened this issue Nov 30, 2022 · 3 comments
Closed

CPU usage when idle #132

AlexanderPavlenko opened this issue Nov 30, 2022 · 3 comments

Comments

@AlexanderPavlenko
Copy link

System Information

  • OS: Docker container: Debian bullseye, Host: Ubuntu
  • Ruby: 2.7.7p221
  • Version: 0.7.50
  • OpenSSL: OpenSSL 1.1.1n 15 Mar 2022

Description

An idle thread in a Rails 5.2.8.1 app consumes CPU.

Rack App to Reproduce

Not sure if it's reproducible. Maybe it's not Iodine's thread, but cat /proc/$rails_s_pid/task/*/stack | grep -c nanosleep seems to always be equal to Iodine.threads * 2.
1 worker & 2 threads – no problem. 1 worker & more than 4 threads – problem occurs.

Expected behavior

All threads consume ~0 CPU when idle, strace logs slow

clock_nanosleep(CLOCK_REALTIME, 0, {0, 150000000}, NULL) = 0

Actual behavior

One of the threads consumes ~15% CPU when idle, strace logs fast

clock_nanosleep(CLOCK_REALTIME, 0, {0, 0}, NULL) = 0`
boazsegev added a commit that referenced this issue Dec 2, 2022
@boazsegev
Copy link
Owner

Hi @AlexanderPavlenko ,

Thank you for opening this issue.

It is reproducible to an extent (I need more threads before one of them starts to happily spike).

Although I'm not sure where the math went wrong, it seems to have been caused by an integer overflow in the wind-down timer value (though there should have been a single zero bit there that would protect us in the test value)...

... However I'm not sure if this was the cause because on my computer I've been getting different results and it was harder to reproduce on a 64 bit system (I'm guessing the issue is more pronounced on 32 bit machines as they would have a single bit left before overflow instead of 33 bits left).

Either way, at some point the static_throttle value appears to zero out or otherwise get corrupted.

I pushed a commit with a possible fix. Any change you could test and make sure this solves your issue before I release a patch?

Thanks,
Bo.

@AlexanderPavlenko
Copy link
Author

Any change you could test and make sure this solves your issue before I release a patch?

It does, thank you very much!

@boazsegev
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants