0

ubuntu top

I just installed 23.10 a few days ago and this started this morning.

I tried to run git status and it seemed to hang. Then VSCode had to unexpectedly close. Then Chrome said it's taking a while so wants to Force Quit or Wait. So I restarted and checked top and see that. How can I diagnose the problem and solve it?

I'm actually not in the middle of any git commands and just have VSCode open, not doing anything. But I do see the TypeScript spinner at the bottom right continuing to circle continuously.

even worse

I only have one VSCode window open now.

mLstudent33
  • 739
  • 1
  • 11
  • 33

1 Answers1

2

cpu usage is not sufficient to determine what your performance bottleneck might be.

Load average is a partial indicator, but still not all that helpful.

Recent linux kernels include something called "stall pressure information" that can identify what resource (out of cpu, I/O, memory) processes are waiting for. Ubuntu 22.04 includes a new enough kernel to include this. This can be a really good diagnostic, but it it is so new that there are few or no tools to monitor it yet.

For a really primitive look, you can try

(cd /proc/pressure && grep . *)

and look for non-zero avg numbers. Delving in what all that means can be long, and is probably worthy of another question.

Having said that, vscode can be a bit of a resource hog. Looking at what is in your top, I can see several indicators that this could be your problem.

vscode by default will try to recursively scan some or all of your filesystem and all of your code directories. Specifically:

  • rg ("ripgrep") will recursively read every file and look for things
  • by default, vscode will repeatedly run git status in every code directory even if you don't have a git repo there. If you have deep data directories this can be a major performance hit. I've seen it start multiple git status runs even when a previous one didn't finish yet.
  • vscode itself (I assume code in your top listings) also does some recursive scanning to create a filename completion cache. It doesn't limit this to your home directory, I have seen it scanning other user's home directories too.
  • Just to add insult to injury, vscode by default will traverse symlinks, and if you have a looped symlink, it will scan that forever.
  • I have seen claims that some of these behaviors are caused by (third party?) vscode plugins. However, while some plugins might make this worse, the default vscode installation does all of the above.

I can see evidence for the top three in your top listings. If you are pulling directories from NFS, this can be a super bad performance killer for both nfs client and server.

As a partial mitigation to this, you can put .gitignore files in strategic places to tell vscode what not to scan. This works great for git status but vscode itself, even when configured not to, will randomly ignore them.

It is also possible to edit vscode settings and give it lists of wildcarded directories to not scan. However, there are multiple such options (and you have to set all of them to stop this), and sometimes it ignores those and scans them anyway, and it is tedious to add every single directory you don't want scanned to two or three different lists.

I consider the fact that you can't control or turn off this behavior to be a bug in vscode, but the vscode authors don't see it that way and have failed to fix this over multiple years despite multiple complaints. They have added options to turn off some of these behaviors, but as I said, some of those options don't work consistently.

user10489
  • 4,051