How to know what goes bad?
Once you decide to optimize your system, it would be time to find which points can be improved. To achieve this, you can use these tools:
ps
This tool allows you to view what processes are running in your system. The range of the process you can see goes from your own ones to all-wide system processes. This command shows the PID for the process, the terminal associated, the accumulated time and the name of the process.
You can use ps to monitor what processes are running on your system and which are extensively using the CPU.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
fernape 2474 0.0 0.1 53944 1648 tty1 Ss 13:02 0:00 -bash
fernape 2577 0.0 0.1 52732 1180 tty1 S+ 13:02 0:00 /bin/sh /usr/X11R
fernape 2609 0.0 0.0 5476 720 tty1 S+ 13:02 0:00 xinit /etc/X11/xi
fernape 2801 0.0 1.1 134360 11768 tty1 S 13:03 0:00 /usr/bin/gnome-se
fernape 2854 0.0 0.0 8796 812 tty1 S 13:03 0:00 /usr/bin/dbus-lau
fernape 2899 0.1 0.9 73576 10112 tty1 S 13:03 0:01 /usr/libexec/gcon
fernape 2962 0.0 0.0 5244 972 tty1 S 13:03 0:00 /usr/bin/gnome-ke
fernape 3180 0.0 0.1 53952 1652 pts/0 Ss 13:07 0:00 bash
fernape 3249 0.0 0.1 53952 1628 pts/1 Ss 13:09 0:00 bash
fernape 3535 0.0 0.0 5440 828 pts/0 R+ 13:18 0:00 ps u
top
If you liked ps, you will like top. Top is a very efficient tool to keep track of processes continuously. The tool is invoked by running top at the prompt. With top, you can list processes ordered by CPU or memory usage. To know more about top, please read this article: Using Top More Efficiently.
vmstat
vmstat provides information about virtual memory, processes, cpu and more. It can be useful to monitor your global system statistics. This tool is a compilation of information that can be gathered from other well-known UNIX commands
[fernape@Hammer ~]$ vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 598412 17444 222484 0 0 258 39 1040 211 6 2 86 7
time
This is a little but useful tool to measure execution times. It takes a command as an argument. Then executes it and shows a brief statistic about time spent by the process. This can help you to find out if a command takes more time than expected. Of course, this is specially useful if you are dealing with a program developed by you, so you can modify your sources and compile again to compare results.
[fernape@Hammer ~]$ time ls -R >/dev/null
real 0m0.117s
user 0m0.057s
sys 0m0.046s
x11perf
x11perf performs a benchmark over the X server. This command is invoked running x11perf from prompt. It can take a lot of parameters but running x11perf with -all parameter reveals a lot of information (but it will take a while...).
Obviously this information is not very useful if we can not compare it with other. Here is when x11perfcomp is in order. x11perfcomp is a shell script that compares two outputs generated by x11perf. Now, the way to analyze your X server performance is clear: take a snapshot of your server performance, make some changes in the configuration file and other system settings (remember that X window system uses shared memory and other IPC mechanisms that can affect performance), run x11perf again and finally, compare the results with x11perfcomp.
Below is a truncated output of x11perf. It is a very configurable tool, you can specify certain performance tests or tell him to run all available tests.
[fernape@Hammer ~]$ x11perf -all
x11perf - X11 performance program, version 1.5
The X.Org Foundation server version 60801000 on :0.0
from Hammer
Sun Apr 2 13:21:41 2006
Sync time adjustment is 0.0895 msecs.
40000000 reps @ 0.0001 msec (6890000.0/sec): Dot
40000000 reps @ 0.0001 msec (7910000.0/sec): Dot
40000000 reps @ 0.0001 msec (7890000.0/sec): Dot
40000000 reps @ 0.0001 msec (7790000.0/sec): Dot
40000000 reps @ 0.0001 msec (8290000.0/sec): Dot
200000000 trep @ 0.0001 msec (7720000.0/sec): Dot
50000000 reps @ 0.0001 msec (10100000.0/sec): 1x1 rectangle
Results can be saved by redirecting the output of x11perf to a file. I executed x11perf once and saved the results in test1 file, then I changed some settings in my xorg.conf file and executed the benchmark again saving results in test2 file. Then I compared them:
[fernape@Hammer ~]$ x11perfcomp test1 test2
1: test1
2: test2
1 2 Operation
-------- -------- ---------
8310000.0 8140000.0 Dot
It appears that my changes were not very appropriate.
When x11perf is used, a white window is showed in the screen as you can see in the picture below. To avoid benchmarking result modification, don't touch that window nor move the mouse over it. The window will disappear when the tests are finished.
hdparm
One of the most important devices in your machine is the hard drive. It is used whenever a new process is loaded, when a memory region is swapped from memory to hard disk and when it is restored from the swap partition to memory again. And because UNIX like systems makes an extensively use of files for almost everything, it is very important to set up the hard disk properly. Hdparm helps you in benchmarking and setting your hard disk.
For now I only show you how to perform a test for your hard disk. If you are impatient and want to know what parameters you can set, read the next section: “Tuning your system”
To perform the test, type (change /dev/hda to match your hard disk.):
[root@Hammer ~]# hdparm -tT /dev/hda
/dev/hda:
Timing cached reads: 1656 MB in 2.00 seconds = 828.13 MB/sec
Timing buffered disk reads: 102 MB in 3.03 seconds = 33.71 MB/sec
I executed hdparm from root account since it is a restricted tool. We can see transfer rates for cached reads and buffered disk reads. If you want to see your current settings, try:
[root@Hammer ~]# hdparm /dev/hda
/dev/hda:
multcount = 16 (on)
IO_support = 1 (32-bit)
unmaskirq = 1 (on)
using_dma = 1 (on)
keepsettings = 0 (off)
readonly = 0 (off)
readahead = 256 (on)
geometry = 65535/16/63, sectors = 80026361856, start = 0
I recommend you to run the test at least five times to take the mean value. And it is important not to use the rest of the system if it is possible, so the test will be not affected by other block disk requests.
------------------------
Best Regards,
eUKShane
http://www.eukhost.com
Enjoy