How come the top command displays >80% CPU idle time but individual processes use >80% CPU?

How come the top command displays >80% CPU idle time but individual processes use >80% CPU?

Please see screenshot below. The values highlighted jump between 80 and 95 percent.

在此输入图像描述

As you can see, the postgres process is taking up all the CPU. However, the user processes percentage is only 5%. As a matter of fact, the majority of the CPU is considered idle. The dashboard on Google Cloud also says that the machine has most CPU idle.

I've collected information here Linux "top" command: What are us, sy, ni, id, wa, hi, si and st (for CPU usage)?

and here: https://scoutapm.com/blog/understanding-linuxs-cpu-stats

The latter source specifically says that databases are part of the 'user space' part. How can this discrepancy be explained? Does it have something to do with different CPU cores?

Update:

Pressing 1 after doing the top command displays cpu use per core:

在此输入图像描述

There are 18 (!) CPU cores. As you can see, one of them is totally eaten up by postgres but the rest is empty. Am I to understand that the %CPU as listed in the top command only shows how much it takes of a single core? This was not clear to me from the sources I have found.

Taking a more solution oriented approach: Adding more cores won't do anything. Rather expanding the size of the CPU running the postgres process could potentially lower the CPU percentage it uses?

答案1

As you can see, the postgres process is taking up all the CPU.

No, it's taking up a single CPU core - that's what 100% under Unix/Linux means. And even that is not precise.

Your postgres process may have two active threads each taking 50% of two different CPU cores and top / ps will report 100%.

Does it have something to do with different CPU cores?

Yes.

As you can see, one of them is totally eaten up by postgres but the rest is empty.

On your screenshot there are two busy CPU cores, one 88%, another one 9%. Their sum is close to what your posgres is using.

Adding more cores won't do anything.

It depends however in your particular situation it seems like whatever workload you're running it's bounded by single-threaded CPU performance, so you're correct.

Rather expanding the size of the CPU running the postgres process could potentially lower the CPU percentage it uses?

I'm not sure what you mean.

相关内容