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

Constant events=POLLIN -> CPU load #523

Closed
jan-vandenberg opened this issue Mar 10, 2018 · 7 comments
Closed

Constant events=POLLIN -> CPU load #523

jan-vandenberg opened this issue Mar 10, 2018 · 7 comments

Comments

@jan-vandenberg
Copy link

jan-vandenberg commented Mar 10, 2018

I'm running wee-slack with legacy tokens (WeeChat 2.0.1/websocket-client (0.47.0)) and everything runs fine except my weechat process uses 2-5% of my CPU constantly . I have other (non-Slack) weechat instances on the same machine that don't have this problem, so I guess its related to the websocket?

Because when I strace my process, this comes flying across the screen 100s of times:

poll([{fd=5, events=POLLIN}, {fd=7, events=POLLIN}, {fd=0, events=POLLIN}, {fd=18, events=POLLIN}, {fd=10, events=POLLIN}, {fd=47, events=POLLIN}, {fd=15, events=POLLIN}], 7, 8) = 0 (Timeout)
fcntl(5, F_GETFD) = 0
fcntl(7, F_GETFD) = 0
fcntl(0, F_GETFD) = 0
fcntl(18, F_GETFD) = 0
fcntl(10, F_GETFD) = 0
fcntl(47, F_GETFD) = 0
fcntl(15, F_GETFD) = 0

Any tips how I can debug this further?

@tfheen
Copy link
Collaborator

tfheen commented Mar 10, 2018

I would check which of those fds, if any, are the websocket fd. lsof -p pid-of-weechat should tell you. We just hook into weechat's hook_fd, so maybe that's doing polling?

@tfheen
Copy link
Collaborator

tfheen commented Mar 10, 2018

Does https://err.no/p/2018-03-10-V1Vioqnb6ys/stdin make it better for you? (Feel free to adjust the wanted_interval to something higher and see how that works.)

@jan-vandenberg
Copy link
Author

Yes! That patch indeed does seem to impact the CPU load/strain quite a bit!
I've tested some different wanted_interval numbers (up to 10000) and this even further reduces the CPU strain (and makes strace very quiet), however it also makes wee-slack unusable: messages/history don't appear.
I've returned to the default wanted_interval values from the diff and will test this a little bit longer.
Thanks!

@tfheen
Copy link
Collaborator

tfheen commented Mar 10, 2018

Numbers above 1000 probably won't make stuff any better, we have other timers that fire at 1s intervals so you'll hit those. If 100 is ok and seems to work without side effects, I'll test that too and look at merging it.

tfheen added a commit that referenced this issue Mar 10, 2018
If there's more work, schedule ourselves more often, if there's less,
back off a bit to lessen the CPU load.

Fixes: #523
@jaywilliams
Copy link
Contributor

This definitely lowers the overall CPU usage. I'm trying it on my slow netbook computer, and the CPU usage dropped from 25% when idling to 5% idling.

@jaywilliams
Copy link
Contributor

I've been merging and using the https://github.com/wee-slack/wee-slack/tree/adaptive-eventrouter-timer branch for a while now, and it makes a huge difference.

Is there any reason why this hasn't been merged into the master branch? I'm assuming everyone would appreciate the extra CPU cycles.

@sondr3
Copy link

sondr3 commented Sep 19, 2018

I'd love this as well, I'm using it on a bit more of a beefy computer but Weechat is still using 2-3% CPU all the time, which is a bit crazy to me.

EDIT: Not a very scientific point of view, but I've run both Slack and wee-slack for a couple of hours now, and according to the Energy Monitor in macOS weechat is consuming more energy than Slack is, though it uses an order of magnitude less RAM. So it's a bit of a toss up.

tfheen added a commit that referenced this issue Sep 30, 2018
If there's more work, schedule ourselves more often, if there's less,
back off a bit to lessen the CPU load.

Fixes: #523
david-thorman pushed a commit to david-thorman/wee-slack that referenced this issue Jan 18, 2019
If there's more work, schedule ourselves more often, if there's less,
back off a bit to lessen the CPU load.

Fixes: wee-slack#523
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

4 participants