.tmux: High CPU consumption usage
When running tmux
v2.2 with this .tmux configuration under MSYS2,
CPU usage goes russian mountains, with big spikes attributed to a system
process.
This doesn’t happen when running tmux
without this .tmux.conf
.
I suspect an issue with some system call such as battery level.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 36 (16 by maintainers)
Commits related to this issue
- Merge branch 'optimizations' into master closes #50, closes #247 — committed to cgxxv/tmuxc by gpakosz 4 years ago
- Merge branch 'optimizations' into master closes #50, closes #247 — committed to cgxxv/tmuxc by gpakosz 4 years ago
- Respect clock format in the status line (#50) Added the new `NORD_TMUX_STATUS_TIME_FORMAT` environment variable that stores the time format for the status bar element based on the value of the `clo... — committed to Evans9610/.tmux by perryjiang 4 years ago
- Merge branch 'optimizations' into master closes #50, closes #247 — committed to spikewj/.tmux by gpakosz 4 years ago
In case anyone here is using OS X + Homebrew you can install tmux directly from their git repository:
Start tmux again and you will be able to use tmux_conf_theme_status_right without experiencing high CPU usage.
My mistake.
By now,
#{loadavg}
is you use it is refreshed in a background job, at most everystatus-interval
seconds#{uptime_s}
, uptime information is refreshed in a background job every seconds otherwise every minute#{battery_bar}
and#{battery_percentage}
is always refreshed in a background job at most every minute#{battery_status}
is refreshed when the status bar is refreshed (everystatus-interval
seconds)#{username}
is refreshed when the status bar is refreshed (everystatus-interval
seconds)#{root}
is refreshed when the status bar is refreshed (everystatus-interval
seconds)#{hostname}
is refreshed when the status bar is refreshed (everystatus-interval
seconds)So that “heartbeat” must correspond to tmux refreshing the status line every
status-interval
seconds. Keep also in mind tmux refreshes the status bar when you hit<prefix>
.Hope that sheds some light 🙂
I was having this same issue on a Centos 6.9 server running tmux 2.4.2.gf.el6. After reading these comments I edited the ‘.tmux.conf’ to change _username and _hostname functions to be specific:
_username() {
echo "$USER"
}
_hostname() {
echo "$HOSTNAME"
}
I also removed all the battery references and most of the “#{xxxx}” references from tmux_conf_theme_status_right:tmux_conf_theme_status_right=' %R , %d %b | #{username} | #{hostname} '
This has fixed the High CPU usage for me for now. On the other hand i have a feeling the issues is related to “#{pane_tty}” because everywhere it is referenced and it gets called, my CPU usage instantly goes to 100%.Yes it definitely looks like my configuration is affected by https://github.com/tmux/tmux/issues/889.
If you do
You will notice that
#{username}
and#{hostname}
implementation expands toand
Added label
external
because while I could find a way to optimize things, it seems forking in Cygwin and MSYS2 is generally sow and that’s something I can’t really improve.BTW @Cyan4973, with Windows 10 creators update, if you uninstall and reinstall Bash for Windows (to get it updated to Xenial instead of Trusty), this configuration works like a charm provided you replace
bold
withnone
in your~/.tmux.conf.local
copy since currently the new Windows console has troubles applying both colors and bold attributes to rendered text.@gpakosz Could you merge this branch to master or are there relevant parts like testing missing?
I’ve been using the optimizations branch for more than a month without excess CPU usage. Latest pull is still good.
👋
I’m close to landing the
optimizations
branch, those following this issue can you please give it a try?Then hit
<prefix> + r
to reload the configuration.Thanks! 🙏
@hg-zt
Thanks for testing.
Yeah I parse
tmux_conf_theme_status_left
andtmux_conf_theme_status_right
content to producestatus-left
andstatus-right
values. In the process#{username}
,#{root}
and#{hostname}
are respectively replaced by:#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)
#(cut -c3- ~/.tmux.conf | sh -s _root #{pane_tty} #D)
#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)
Which you can see when you inspect the output of
tmux show -gv status-right
.Every time you change the “current pane”, the values of
#{pane_tty}
and#D
change andtmux
executes the command again. This is effectively needed because you want the username, root flag and hostname information to update as quickly as possible. And when you don’t change pane,tmux
will execute the commands again everystatus-interval
seconds which is set to15
in theoptimizations
branch.Finally, the implementation of
_username()
,_root()
and_hostname()
requires doing non trivial work after having inspected the output ofps
for the TTY specified by#{pane_tty}
. From there it finds out which user is running the command and whether the user is the root user. It also tries out to detect the current command is assh
process and if yes does more work to find out which is the remote user connected to the remote host. I still need to figure out how to minimize the work needed there.@gpakosz
Hi, I’ve tried the latest
optimizations
and reset options in.tmux.conf.local
for testing. I found all thebattery
parts no longer cause significant cpu usage even on an arm platform. While the last parts oftmux_conf_theme_status_right
(#{username}#{root} | #{hostname}
) still cause spikes (see below). After removing the these parts, spikes disappeared.PS. Here’s the output of
pidstat -T CHILD -p $tmux_server_pid 1
for the default.tmux.conf.local
output
It appears every ~15 secs. On a desktop computer it consumes less
usr-ms
andsystem-ms
.I’m wondering if this could be related? https://github.com/tmux/tmux/issues/889
When I set
tmux_conf_theme_status_right=''
, the issue seems to vanish.Ninja Edit: I’m fairly certain that this is the problem (at least for me). As soon as I have any
#
-style elements intmux_conf_theme_status_right
, I see the CPU spike again. Hopefully once the patch for the above issue reaches a release, it won’t be a problem. Sorry for the spam!Hello Yann,
I got tmux working on my workstation within msys2 but well there’s no battery to query. I can’t seem to reproduce the spikes you’re mentioning.
Anyways, in the meantime I try on a laptop what you can do is edit your local
~/.tmux.conf.local
copy (see instructions if you didn’tcp ~/.tmux.conf/.tmux.conf.local ~/.tmux.conf.local
. And then replaceby
Hmm, I gave it a spin and installed
tmux-git-2.1.263.g5083e93-1
package which reports2.2
version.When I launch tmux with my configuration, tmux crashes 😦 Gonna investigate more