Section 2.7. sar Command


2.7. sar Command

The system activity reporter (sar) can provide live statistics or can be activated to record historical CPU statistics. This can be of tremendous value because you may identify long-term patterns that you might have missed when taking a quick look at the system. Also, historical data provides a reference for what is "normal" for your system.

2.7.1. sar Default Output

The following example shows the default output of sar, which is also the -u option to sar. An interval of 1 second and a count of 5 were specified.

$ sar 1 5 SunOS titan 5.11 snv_16 sun4u    02/27/2006 03:20:42    %usr    %sys    %wio   %idle 03:20:43      82      17       0       1 03:20:44      92       8       0       0 03:20:45      91       9       0       0 03:20:46      94       6       0       0 03:20:47      93       7       0       0 Average       91       9       0       0 


sar has printed the user (%usr), system (%sys), wait I/O (%wio), and idle times (%idle). User, system, and idle are also printed by the vmstat command and are defined in 2.2. The following are some additional points.

  • %usr, %sys (user, system). A commonly expected ratio is 70% usr and 30% sys, but this depends on the application. Applications that use I/O heavily, for example a busy Web server, can cause a much higher %sys due to a large number of system calls. Applications that spend time processing userland code, for example, compression tools, can cause a higher %usr. Kernel mode services, such as the NFS server, are %sys based.

  • %wio (wait I/O). This was supposed to be a measurement of the time spent waiting for I/O events to complete.[3] The way it was measured was not very accurate, resulting in inconsistent values and much confusion. This statistic has now been deliberately set to zero in Solaris 10.

    [3] Historically, this metric was useful on uniprocessor systems as a way of indicating how much time was spent waiting for I/O. In a multiprocessor system it's not possible to make this simple approximation, which led to a significant amount of confusion (basically, if %wio was non-zero, then the only useful information that could be gleaned is that at least one thread somewhere was waiting for I/O. The magnitude of the %wio value is related more to how much time the system is idle than to waiting for I/O. You can get a more accurate waiting-for-I/O measure by measuring individual thread, and you can obtain it by using DTrace.

  • %idle (idle). There are different mentalities for percent idle. One is that percent idle equals wasted CPU cycles and should be put to use, especially when server consolidation solutions such as Solaris Zones are used. Another is that some level of %idle is healthy (anywhere from 20% to 80%) because it leaves "head room" for short increases in activity to be dispatched quickly.

2.7.2. sar -q

The -q option for sar provides statistics on the run queues (dispatcher queues).

$ sar -q 5 5 SunOS titan 5.11 snv_16 sun4u    02/27/2006 03:38:43 runq-sz %runocc swpq-sz %swpocc 03:38:48     0.0       0     0.0       0 03:38:53     1.0      80     0.0       0 03:38:58     1.6      99     0.0       0 03:39:03     2.4     100     0.0       0 03:39:08     3.4     100     0.0       0 Average      2.2      76     0.0       0 


There are four fields.

  • runq-sz (run queue size). Equivalent to the kthr:r field from vmstat; can be used as a measure of CPU saturation.[4]

    [4] sar seems to have a blind spot for a run queue size between 0.0 and 1.0.

  • %runocc (run queue occupancy). Helps prevent a danger when intervals are used, that is, short bursts of activity can be averaged down to unnoticeable values. The run queue occupancy can identify whether short bursts of run queue activity occurred.[5]

    [5] A value of 99% for short intervals is usually a rounding error. Another error can be due to drifting intervals and measuring the statistic after an extra update; this causes %runocc to be reported as over 100% (e.g., 119% for a 5-second interval).

  • swpq-sz (swapped-out queue size). Number of swapped-out threads. Swapping out threads is a last resort for relieving memory pressure, so this field will be zero unless there was a dire memory shortage.

  • %swpocc (swapped out occupancy). Percentage of time there were swapped out threads.

2.7.3. Capturing Historical Data

To activate sar to record statistics in Solaris 10, use svcadm enable sar.[6] The defaults are to take a one-second sample every hour plus every twenty minutes during business hours. This should be customized because a one-second sample every hour isn't terribly useful (the man page for sadc suggests it should be greater than five seconds). You can change it by placing an interval and a count after the sa1 lines in the crontab for the sys user (crontab -e sys).

[6] Pending bug 6302763; the description contains a workaround.




Solaris Performance and Tools(c) Dtrace and Mdb Techniques for Solaris 10 and Opensolaris
Solaris Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris
ISBN: 0131568191
EAN: 2147483647
Year: 2007
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net