-
Notifications
You must be signed in to change notification settings - Fork 652
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
100% CPU usage [after sending message] on Swift ARM #1337
Comments
The common cause for this is that we’re spinning in |
@Bouke Thanks for the detailed report! As @Lukasa points out, this points to us not properly processing some event so If you can, would you mind to attach a few lines of the output of
whilst in the 100% CPU spin loop? Also, is this 32 or 64 bit? |
Based on the target triple it’s 32-bit: at least the OS is. |
strace output for
strace output for my own application:
(Note that this is not an official Swift build, but provided by the Swift-ARM community. Official builds don't target ARM, nor 32 bit. See also: https://github.com/uraimo/buildSwiftOnARM and https://swift-arm.com) |
@Bouke thanks for the fast response. Interestingly, this is the
(the only difference to the previous one is the |
Sure, that would be:
Thank you as well. |
einval is a baffling response, why isn’t that causing us to error out? |
@Bouke wow, that's
|
could we have
alongside the same |
I think this is what you're asking for?
|
it's this guy: https://github.com/apple/swift-nio/blob/master/Sources/NIO/Selector.swift#L552 |
thank you @Bouke ! this should allow us to debug it, clearly we're doing the timerfd wrong :) |
oooh I think timerfd needs to be 64bit always |
yes, this line
must be
|
@Bouke if you want, you could make this fix yourself, I think you literally just need to add |
docs are here:
|
Hmm yeah that makes sense! (Although I haven't the faintest clue what this does)
|
That fixed the issue for the chat client. I'm now going to test against my own application. |
@Bouke by reading 64 bits from the "timerfd" you just tell the kernel "ok, thanks, I have processed the timer you woke me up for". But we didn't read enough and therefore the kernel thought we hadn't processed the timer and told us about the same timer again, straight away, in a loop... |
After compiling for what feels like an eternity (the raspberry's not that fast), I can confirm that this is also the fix for my application. Thanks so much everyone! |
@weissi shouldn't we use edge triggered for the timerfd and so it should not "matter" ? |
I should have written a test! 🤦♀ |
@Bouke You don't have to compile on the Raspi, you can use X-compilers, e.g. https://github.com/CSCIX65G/SwiftCrossCompilers |
@normanmaurer because of deregistrations, we sometimes go back to the kernel to have all events redelivered so we can’t use edge triggered. Also, reading off that the timer fired is still very important even in edge-triggered as we would otherwise only ever get one event (because we never acknowledge it). |
Expected behavior
When there's not much going on, little CPU usage. Increase in CPU while there's activity.
Actual behavior
Continuously high CPU usage, even when there's no network traffic.
Steps to reproduce
I'm not sure what exactly triggers the problem in my application, but I've observed the same problem with the chat client. So including those steps here:
swift run NIOChat(Server|Client)
)SwiftNIO version/commit hash
Tested against version 2.12.0 and master (f44fe0b).
Swift & OS version (output of
swift --version && uname -a
)Flame graph
Some symbols are missing due to
perf
version mismatch (I think). Both the chat client and my application ("my-home") are included. Attached are the zoomable flame graphs: flame-graphs.zip.The text was updated successfully, but these errors were encountered: