1

I am running a R script and it is actually a long for loop.

Here is a screenshot of the "top" command. You can see that it says R is using 100 % CPU but on the top line, it says 4.2% usage for user processes. What does this mean? Does it mean that the CPU has multiple cores and I am only using one?

enter image description here

1
  • I believe that it means that when 'top' was executing, it was using 4.2% of the CPU time and when it listed the programs, the first line had 100% of the CPU time. If you add up the CPU time, there is 100.9% in the first 4 lines. – LDC3 Aug 5 '14 at 4:06
0

First of all, yes - if you have a multi-core system you can have multiple processes at 100% (the process list shows the utilization of a theoretical single core) or for multithreaded processes you can have a single process above 100%. The overall CPU usage might be 25%, 50% etc. - because the top default is for the first CPU figures to be an aggregate of all CPUs on the system. You will get a better view if you press 1 with top running - it will split out each CPU.

With that said, the us(er), sy(stem), ni(ce) and id(le) buckets are also relevant. The R program does not seem to be hammering the CPU in the loop and so the CPU is mostly in the Idle bucket. I am not super familiar with R - you might want to add some debug to see what it is waiting for, if you can optimize it to better utilize the CPU (assuming you are aiming for it to be CPU bound). Similarly you could have a process hammering the disk and have a low percentage User but a high Wa(it) figure while you wait to page data to/from the disk.

If R was churning in the loop doing calculations/sorts or similar constantly this would shift overall CPU usage to the User bucket (or if you nice the process it would shift to the nice bucket). The system bucket might see an uptick if you were doing large in-memory scans and sorts (though then it would not necessarily be assigned to a process in the list). Right now though, it looks like your system is pretty lightly loaded running the current loop.

1
  • I'll look at my R script. R is not very friendly to multiple cores but my for loop was heavy in computation. I'll try to analyze my script again and make sense of the numbers. Thanks. – masfenix Aug 5 '14 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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