0

Why does "top" command shows two different values for a Linux server with only just one CPU. I understand that it can differs when there is a multi core processor but in this case I'm using a AWS LightSail $5 instance with only one CPU 512 MB RAM, 1 vCPU, 20 GB SSD.

enter image description here

In Amazon console it shows that the CPU usage don't pass the 10% usage, however the applications is down. When I look at the usage I just saw this nearly 100% usage.

Why does this happens? Which value should I consider for measuring my VM utilizations percentage?

1

In the Line %Cpu(s) top splits the CPU usage into categories:

       us, user    : time running un-niced user processes
       sy, system  : time running kernel processes
       ni, nice    : time running niced user processes
       id, idle    : time spent in the kernel idle handler
       wa, IO-wait : time waiting for I/O completion
       hi : time spent servicing hardware interrupts
       si : time spent servicing software interrupts
       st : time stolen from this vm by the hypervisor

Your used CPU consists of ALL those values added up. That means in this case:

7.3 + 0.0 + 0.0 + 4.3 + 0.0 + 0.0 + 88.3 = 99,9

In Amazon LightSail, as described in this other answer, "LightSail will not let you use all of the power of your vCPU all of the time so it has been capped."

It's really not that obvious in my opinion and there should be a total CPU-value in top but sadly, there isn't.

You could use another program called "htop" (install it on the server), it displays information much more comfortable, e.g. total CPU usage per core for example.

It looks like this:

enter image description here

  • Great explanations. I would like to accept your both answers. both are complementary. @paul_gallon explains better why this happens on Amazon Light Sail. If you could write it down i will be happy to accept your answer instead. – Daniel Santos Mar 14 '18 at 14:39
  • 1
    @DanielSantos nah it's fine, I'm here for learning, not for points. – Broco Mar 14 '18 at 14:44
  • a despite of... "htop" was a great advice, i'm using it now. Do yout know some app that allows me to check CPU usage history also on command line? – Daniel Santos Mar 14 '18 at 14:46
  • 1
    Sadly htop can't do that, it's just for live monitoring. You could use top for that in batch mode like this top -b -d 10 > /path/to/yourlogfile.log which will log every 10 seconds (note that this will creat a LOT of data, consider bigger intervals). Also you could use atop (haydenjames.io/use-atop-linux-server-performance-analysis) which has a log-review function built in. But I gotta admit, long term performance analysis is a pain in the butt on the CLI; when I need performance logging I usually go for graphical monitoring tools. – Broco Mar 14 '18 at 15:17
1

If you look at the end of the third line in your screenshot, 88.3% of the CPU time is being 'stolen' by the host machine. This could be due to your application using a lot of CPU time for more than a short burst of activity. LightSail will not let you use all of the power of your vCPU all of the time so it has been capped. Your application is using 94.4% of what is left over.

Source for top interpretation: https://linuxaria.com/howto/understanding-the-top-command-on-li Source for LightSail resource usage: https://aws.amazon.com/lightsail/faq/

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.