Dave Howorth mailto:dhoworth@mrc-lmb.cam.ac.uk scribbled on Wednesday, August 24, 2005 7:50 AM:
Richard Mixon (qwest) wrote:
Jerry Feldman mailto:gaf@blu.org scribbled on Wednesday, August 24, 2005 5:55 AM:
On Wednesday 24 August 2005 1:38 am, Richard Mixon (qwest) wrote:
We noticed a significant different between the "percentage CPU" reported by TOP for a process (a Java instance of Tomcat) and that reported by issuing "ps -o pid,pcpu <process-id>". TOP indicated that the process was using 99% CPU, but "ps" just showed it using 40%.
I have google and googled, read the man/info pages - but cannot find any explanation for how they each arrive at their figures.
Any ideas or explanations are appreciated/welcome.
the top(1) command uses a sample and measures the percentage of elapsed CPU time between samples. PS is a single sample where percentage of CPU time is expressed in a ratio between "CPU time used divided by the time the process has been running".
Jerry, thanks - this sounds good. But if top is time averaging cpu usage, I would expect it to report a lower percentage cpu usage than ps does.We are seeing the opposite. BTW, this is a dual Xeon with hyperthreading turned on.
Any other ideas?
Interesting question. I just started this: perl -e '{while(1){}}' & on a pretty idle dual Xeon running SuSE 9.2. Top shows me
Cpu(s): 25.0% us, 0.0% sy, 0.0% ni, 74.5% id, 0.5% wa, 0.0% hi, 0.0% si
1550 root 25 0 8872 1400 8220 R 99.9 0.1 6:01.36 perl
and I can use '1' to see the indivual HT that is running the process.
ps on the other hand shows this:
suse1:~ # ps -o pid,pcpu 1550 PID %CPU 1550 8.8 suse1:~ # ps -o pid,pcpu 1550 PID %CPU 1550 9.2 suse1:~ # ps -o pid,pcpu 1550 PID %CPU 1550 9.6 suse1:~ # ps -o pid,pcpu 1550 PID %CPU 1550 10.0 suse1:~ # ps -o pid,pcpu 1550 PID %CPU 1550 14.1 suse1:~ # ps -o pid,pcpu 1550 PID %CPU 1550 30.1
So it looks to me that ps is doing some kind of long-term averaging.
BTW, the same test on a single P4 running SuSE 9.3 says:
dhoworth@cpepc210-3:/tmp/Perl-Tidy-20031021> ps -o pid,pcpu 22111 PID %CPU 22111 108
from the get go. So who knows what's going on! top gets my vote for being the truthful one.
Better get back to my real work now ...
Dave - thanks for the test and associated insight. Hmm - we had wanted to have a script use ps to tell us if a particular java process started maxing out the cpu. Can't do that with top, so need to think about this more - or else get a real monitoring framework like nagios. Thanks again - Richard