- 310 -
14.2.2 Process Priorities
The operating system also has the ability to prioritize the processes in terms of providing CPU time by allocating process priority levels. CPU priorities provide a way to throttle high-demand CPU
processes, thus giving other processes a greater share of the CPU. If you find there are other processes that need to run on the same machine, but it wouldnt matter if they were run more
slowly, you can give your application processes a much higher priority than those other processes, thus allowing your application the lions share of CPU time on a congested system. This is worth
keeping in mind. If your application consists of multiple processes, you should also consider the possibility of giving your various processes different levels of priority.
Being tempted to adjust the priority levels of processes, however, is often a sign that the CPU is underpowered for the tasks you have given it.
14.3 RAM
Maintaining watch directly on the system memory RAM is not usually that helpful in identifying performance problems. A better indication that memory might be affecting performance can be
gained by watching for paging of data from memory to the swap files. To clarify the term paging: most current operating systems have a virtual memory that is made up of the actual real system
memory using RAM chips, and one or more swap files on the system disks. Processes that are currently running are operating in real memory. The operating system can take pages from any of
the processes currently in real memory, and swap them out to disk. This is known as paging. Paging leaves free space in real memory to allocate to other processes that need to bring in a page from
disk.
[2] [2]
The term swapping refers to moving entire processes between main memory and the swap file. Most modern operating systems no longer swap processes; instead, they swap pages from processes, thus the term paging.
Obviously, if all the processes currently running can fit into the real memory, there is no need for the system to page out any pages. However, if there are too many processes to fit into real memory,
paging allows the system to free up system memory to run further processes. Paging affects system performance in many ways. One obvious way is that if a process has had some pages moved to disk
and the process becomes runnable, the operating system has to pull back the pages from the disk before that process can be run. This leads to delays in performance. In addition, both the CPU and
the disk IO subsystem spend time doing the paging, reducing available processing power and increasing the load on the disks. This cascading effect involving both the CPU and IO can degrade
the performance of the whole system in such a way that it may be difficult to even recognize that the paging is the problem. The extreme version of too much paging is thrashing, in which the
system is spending so much time moving pages around that it fails to perform any other significant work. Beyond this, you would be likely to have a system crash.
As with runnable queues see Section 14.2
, a little paging of the system does not affect performance enough to cause concern. In fact some paging can be considered good. It indicates that
the systems memory resources are being fully used. But at the point where paging becomes a significant overhead , the system is overloaded.
Monitoring paging is relatively easy. On Unix, the utilities vmstat and iostat provide details as to the level of paging, disk activity, and memory levels. On Windows, the performance monitor has
categories to show these details, as well as being able to monitor the system swap files.
If there is more paging than is optimal, the systems RAM is insufficient or processes are too big. To improve this situation, you need to reduce the memory being used by reducing the number of
- 311 - processes or the memory utilization of some processes. Alternatively, you can add RAM. Assuming
that it is your application that is causing the paging otherwise, either the system needs an upgrade, or someone elses processes may also have to be tuned, you need to reduce the memory resources
you are using.
Chapter 4 provides useful recommendations for improving application-memory
usage. When the problem is caused by a combination of your application and others, you can partially
address the situation by using process priorities see Section 14.2
. The equivalent to priority levels for memory usage is an all-or-nothing option, where you can lock a process in memory. This option
is not available on all systems and is more often applied to shared memory rather than to processes, but nevertheless it is useful to know. If this option is applied, the process is locked into real memory
and is not paged out at all. You need to be aware that using this option reduces the amount of RAM available to all other processes, which can make the overall system performance worse. Any
deterioration in system performance is likely to occur at heavy system loads, so make sure you extrapolate the effect of reducing the system memory in this way.
14.4 Network IO