A while back I wrote a post Analyzing Linux System Performance and Finding Bottlenecks. I did’t really give a good explanation of determining if you are CPU bound or not so I am writing this post to clear that up.

As I noted previously the sysstat package can provide a wealth of information. One of my favorite utilities is sar. By default sar outputs a CPU utilization report. Lets take a look at some example output.

The quickest way to see if you need more horsepower is by checking out the idle column. You can see in my example output that as the work day starts the server starts to get a bit stressed, and as the day rolls and we get to midday ive only got about 50% idle.

You might think that is a bit low. Really though most servers are underutilized. I’m sure you’ve heard it before but over 80% of production servers run at less than 20% capacity. That is a good reason to look into server consolidation with a virtualization platform perhaps something like Xen.

Since this is a virtual machine and I have spare cores that could be assigned lets keep investigating if I have a CPU bottleneck.

We have already established that an idle time of 50% isn’t too bad. An idle time habitually less than 20% indicates that the system will not be able to handle a much higher load. If your idle time is regularly less than 5% you might need to add some processing power.

A low idle time in and of itself does not mean you need shiny new cpus (or to add additional virtual cpus in this case). in addition to idle you should look at several other metrics to get a clear picture. First off if your iowait is high you can stop looking for a cpu bottleneck until you have tracked your io bottleneck (faster hard drives, more drives in your raid, move disk heavy service to faster box). iowait higher than about 15% likely indicates an io bottleneck (I have seen some poorly neglected servers with iowaits in the high 60%s. Boy were they pokey, especially the IMAP server that was in that state.)

Moving on past the quick iowait check. Even if your idle time is really low you can check to see if the run queue is heavy or not with sar -q.

Here is the run queue for the same time period. We are looking for runq-sz (number of tasks waiting for run time) consistently greater than 2. Well in my case I look ok. Im starting to see an increase in demand for cpu time but its being handeled well. But since I have some extra cores and since I know that this server has not seen the busy part of the year I will probabbly attach an extra vcpu so I have less to worry about in the comming months.

Whew took a bit to spit that out, hope you enjoyed!


A friend of mine (thanks Scott) commented on something that I neglected to point out. You might want to do a bit of application profiling. Something like a database that has not had optimize tables or vacuum run on it in a long time may present as high iowait. Moving the service might very well alleviate your problem because in the act of moving it you may defrag the database when putting it on the shiny new hardware. So when looking for performance bottle necks metrics cant really tell you if some service or code you have written is just inefficient, either for poor code smells or for lack of maintenance. Just be careful to not sell the farm for a new server when the old one still works just fine.