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 #509

Closed
kxt opened this issue May 15, 2021 · 4 comments · Fixed by #523
Closed

CPU usage when idle #509

kxt opened this issue May 15, 2021 · 4 comments · Fixed by #523

Comments

@kxt
Copy link
Contributor

kxt commented May 15, 2021

version: 0.10.0

I've noticed that an idle zellij process (eg. running only a barebones shell) uses quite a lot of CPU and reduces battery life too. Having multiple panes/tabs makes this more severe.

I found that in pty.rs, each fd is being actively polled to check if new data is available from a client. This can be verified by running zellij with strace, it reports thousands of syscalls per second during steady state (ie. idle).

I've created a proof-of-concept patch that uses async-std to manage io and timeout (for batching updates to reduce render time). With this patch, activity during idle drops significantly, the only activity reported by strace is os_input_output.rs's handle_command_exit looping.

I need someone to review it and discuss whether an approach like this is suitable for zellij and if so, how to move forward (eg. ServerOsApi would need to become and async trait if an approach like this would be used).

@imsnif
Copy link
Member

imsnif commented May 17, 2021

@kxt - this definitely looks like a good direction! I haven't tested this out yet, but how about you whip up a PR and we'll see how it behaves?

Key things to check: performance when dumping lots of lines to the screen (eg. cat a 100000 lines file and time it).

@kxt
Copy link
Contributor Author

kxt commented May 17, 2021

Thank you for your input! I'm going to create 2 PRs:

  • one is some assorted cleanup patches that I created while working on the async code, these are probably not very controversial and can be merged quickly
  • the other is the actual fix for this issue

@kxt
Copy link
Contributor Author

kxt commented May 18, 2021

I've created the first PR with the refactor patches, #521.
For the actual fix, I have some problems figuring out the fakes to investigate some failing testcases.

@imsnif
Copy link
Member

imsnif commented May 18, 2021

First PR merged!
Do feel free to reach out if you want a hand with the fakes. The whole testing framework is a little iffy and we're very eager to replace it :) You can reach out here or on discord, as you like.

kxt added a commit to kxt/zellij that referenced this issue May 18, 2021
This patch fixes zellij-org#509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
kxt added a commit to kxt/zellij that referenced this issue May 19, 2021
This patch fixes zellij-org#509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
kxt added a commit to kxt/zellij that referenced this issue May 19, 2021
This patch fixes zellij-org#509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
kxt added a commit to kxt/zellij that referenced this issue May 19, 2021
This patch fixes zellij-org#509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
kxt added a commit to kxt/zellij that referenced this issue May 19, 2021
This patch fixes zellij-org#509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
kxt added a commit to kxt/zellij that referenced this issue May 19, 2021
This patch fixes zellij-org#509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
kxt added a commit to kxt/zellij that referenced this issue May 21, 2021
This patch fixes zellij-org#509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
imsnif pushed a commit that referenced this issue May 24, 2021
This patch fixes #509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants