13    Managing CPU Performance

You can improve system performance by optimizing CPU resources. This chapter describes how to perform the following tasks:

13.1    Monitoring CPU Performance Information

Table 13-1 describes the tools you can use to gather information about CPU usage.

Table 13-1:  CPU Monitoring Tools

Name Description Reference

ps

Displays current statistics for running processes, including CPU usage, the processor and processor set, and the scheduling priority.

Section 12.3.2

vmstat

Displays information about process threads, virtual memory usage (page lists, page faults, page ins, and page outs), interrupts, and CPU usage (percentages of user, system, and idle times). First reported are the statistics since boot time; subsequent reports are the statistics since a specified interval of time.

Section 12.3.1

uptime

Displays the system load average and the number of jobs in the run queue for the last 5 seconds, the last 30 seconds, and the last 60 seconds. The uptime command also shows the number of users logged into the system and how long a system has been running.

Section 13.1.1

(kdbx) cpustat

Displays CPU statistics, including the percentages of time the CPU spends in various states.

Section 13.1.2

(kdbx) lockstats

Displays lock statistics for each lock class on each CPU in the system.

Section 13.1.3

sys_check

Analyzes system configuration and displays statistics and checks kernel variable settings and memory and CPU resources, and provides performance data and lock statistics for SMP and kernel profiles.

See Section 2.3.3 or see sys_check(8) for more information.

Process Tuner

Displays current statistics for running processes. Invoke the Process Tuner graphical user interface (GUI) from the CDE Application Manager to display a list of processes and their characteristics, display the processes running for yourself or all users, display and modify process priorities, or send a signal to a process.

While monitoring processes, you can select parameters to view (percent of CPU usage, virtual memory size, state, and nice priority) and also sort the view.

Section 13.2.2.1.1

monitor

Collects a variety of performance data on a running system and either displays the information in a graphical format or saves it to a binary file.

See monitor(3) for more information.

top

Provides continuous reports on the state of the system, including a list of the processes using the most CPU resources.

The top command is available on the Tru64 UNIX Freeware CD-ROM. See ftp://eecs.nwu.edu/pub/top for information.

ipcs -a

Displays interprocess communication (IPC) statistics for currently active message queues, shared-memory segments, semaphores, remote queues, and local queue headers. The information provided in the following fields reported by the ipcs -a command can be especially useful: QNUM, CBYTES, QBYTES, SEGSZ, and NSEMS.

See ipcs(1) for more information.

w

Displays the current time, the amount of time since the system was last started, the users logged in to the system, and the number of jobs in the run queue for the last 5 seconds, 30 seconds, and 60 seconds.

See w(1) for more information.

xload

Displays the system load average in a histogram that is periodically updated.

See xload(1X) for more information.

The following sections describe the ps, vmstat, uptime, cpustat, and lockstats commands in detail.

13.1.1    Monitoring the Load Average by Using the uptime Command

The uptime command shows how long a system has been running and the load average. The load average counts the jobs that are waiting for disk I/O, and applications whose priorities have been changed with either the nice or the renice command. The load average numbers give the average number of jobs in the run queue for the last 5 seconds, the last 30 seconds, and the last 60 seconds.

An example of the uptime command is as follows:

# /usr/ucb/uptime
1:48pm  up 7 days,  1:07,  35 users,  load average: 7.12, 10.33, 10.31

The command output displays the current time, the amount of time since the system was last started, the number of users logged into the system, and the load averages for the last 5 seconds, the last 30 seconds, and the last 60 seconds.

From the command output, you can determine whether the load is increasing or decreasing. An acceptable load average depends on your type of system and how it is being used. In general, for a large system, a load of 10 is high, and a load of 3 is low. Workstations should have a load of 1 or 2.

If the load is high, look at what processes are running with the ps command. You may want to run some applications during offpeak hours. See Section 12.3.2 for information about the ps command.

You can also lower the priority of applications with the nice or renice command to conserve CPU cycles. See nice(1) and renice(8) for more information.

13.1.2    Checking CPU Usage by Using the kdbx Debugger cpustat Extension

The kdbx debugger cpustat extension displays CPU statistics, including the percentages of time the CPU spends in the following states:

The cpustat extension to the kdbx debugger can help application developers determine how effectively they are achieving parallelism across the system.

By default, the kdbx cpustat extension displays statistics for all CPUs in the system. For example:

# /usr/bin/kdbx -k /vmunix /dev/mem 
(kdbx)cpustat
 Cpu   User (%)    Nice (%) System (%)  Idle (%)   Wait (%)
===== ========== ========== ========== ========== ==========
    0       0.23       0.00       0.08      99.64       0.05
    1       0.21       0.00       0.06      99.68       0.05

See the Kernel Debugging manual and kdbx(8) for more information.

13.1.3    Checking Lock Usage by Using the kdbx Debugger lockstat Extension

The kdbx debugger lockstats extension displays lock statistics for each lock class on each CPU in the system, including the following information:

For example:

# /usr/bin/kdbx -k /vmunix /dev/mem 
(kdbx)lockstats

See the Kernel Debugging manual and kdbx(8) for more information.

13.2    Improving CPU Performance

A system must be able to efficiently allocate the available CPU cycles among competing processes to meet the performance needs of users and applications. You can improve performance by optimizing CPU usage.

Table 13-2 describes the guidelines to improve CPU performance.

Table 13-2:  Primary CPU Performance Improvement Guidelines

Guidelines Performance Benefit Tradeoff
Add processors (Section 13.2.1) Increases CPU resources Applicable only for multiproccessing systems, and may affect virtual memory performance
Use the class scheduler (Section 13.2.2) Allocates CPU resources to critical applications None
Prioritize job (Section 13.2.3) Ensures that important applications have the highest priority None
Schedule jobs at offpeak hours (Section 13.2.4) Distributes the system load None
Stop the advfsd daemon (Section 13.2.5) Decreases demand for CPU power Applicable only if you are not using the AdvFS graphical user interface
Use hardware RAID (Section 13.2.6) Relieves the CPU of disk I/O overhead and provides disk I/O performance improvements Increases costs

The following sections describe how to optimize your CPU resources. If optimizing CPU resources does not solve the performance problem, you may have to upgrade your CPU to a faster processor.

13.2.1    Adding Processors

Multiprocessing systems allow you to expand the computing power of a system by adding processors. Workloads that benefit most from multiprocessing have multiple processes or multiple threads of execution that can run concurrently, such as database management system (DBMS) servers, Internet servers, mail servers, and compute servers.

You may be able to improve the performance of a multiprocessing system that has only a small percentage of idle time by adding processors. See Section 12.3.1 for information about checking idle time.

Before you add processors, you must ensure that a performance problem is not caused by the virtual memory or I/O subsystems. For example, increasing the number of processors will not improve performance in a system that lacks sufficient memory resources.

In addition, increasing the number of processors may increase the demands on your I/O and memory subsystems and could cause bottlenecks.

If you add processors and your system is metadata-intensive (that is, it opens large numbers of small files and accesses them repeatedly), you can improve the performance of synchronous write operations by using a RAID controller with a write-back cache (see Section 9.4).

13.2.2    Using the Class Scheduler

The class scheduler provides you with a method of controlling the execution of tasks or applications by restricting the length of time that they can access the processor (CPU). For example, daemons such as the print spooler are given less access time. The CPU will then have more time available to perform other tasks. To do this, you specify that the print daemon /usr/lbin/lpd is allowed to use no more than a certain percentage of the available CPU time. You can group resource user identifiers, such as a user's UID (user identification), into classes and assign the required CPU access time to each class.

This feature can help you to allocate system resources so that the most important work receives the required processing time. For example, you might want to run two versions of a production database on your system. One version is used as part of your business operations, while the other is a test copy, with different tuning parameters. You can assign the test database to a different class to prevent it from affecting your daily operations.

To set up and use the class scheduler, you must complete the following steps:

  1. Plan the allocation of CPU resources.

  2. Use class_admin to set up and maintain the class database.

  3. Create classes and add members to the classes.

  4. Verify class entries using the show command.

  5. Save the entries to the database.

  6. Enable class scheduling to start the daemon.

Use the class scheduler commands to monitor and control scheduling as follows:

The following sections suggest a systematic approach to using class scheduling, although it is not necessary to perform tasks in a specific sequence. There are two methods of accessing the class scheduler:

The following reference pages contain detailed information on using the class scheduler commands and options:

The following command displays online help for the class_admin command:

# /usr/sbin/class_admin help
 
 

13.2.2.1    Class Scheduler Overview

To use the class scheduler, you must first create a database file and populate the file with one or more classes. Each class is assigned a CPU value that controls its access to processing time, expressed as a percentage of the total CPU time availability. You can assign one or more applications or groups of applications to a class, identified according to a unique system process identifier such as:

The PID, PGID, and SESS identifiers are usually temporary and do not persist across a reboot, ceasing to exist when a task is completed. They are not stored in the database and have no effect when the system or task is restarted.

After the database is established, you can enable class scheduling. This operation starts a class scheduling daemon and puts the CPU access restrictions into effect. Other commands enable you to review classes, change contents or scheduling parameters, and delete components or entire classes. When a class scheduling database is configured and enabled, you can:

13.2.2.1.1    Related Utilities

The following utilities are also available for use when monitoring and tuning processes:

13.2.2.1.2    Invoking the Class Scheduler

The class scheduler is provided as both a command-line interface and a graphical user interface. You can invoke the class scheduler in several ways, depending on which user environment you are working from:

The following sections focus on using the command-line method, and provide a brief introduction to using the graphical interface. See the online help for more information in using the graphical interface.

13.2.2.2    Planning Class Scheduling

How you allocate CPU resources depends on your system environment and what resources and priorities must be considered. A typical scenario is to assign a higher CPU percentage to interactive tasks so that users do not encounter long response times. Most batch or background processes will be assigned a lower CPU percentage, while some specific background processes might require a higher CPU percentage. For example, if a nightly backup is being performed, you might not want it to have such a low CPU percentage that it does not complete in a reasonable time.

If your system is involved with critical real-time tasks that must take precedence over interactive processes, your course of action might be different. In such cases you should design a baseline that assigns processes to classes. You can then monitor processes and gather user feedback to tune the database by moving tasks from class to class or by changing the CPU access time of the classes.

Do not use the root account to create test processes when you configure class scheduling. Root account processes always take precedence over others, even when assigned to an existing restricted class.

13.2.2.3    Configuring Class Scheduling

Use the class_admin command to configure an initial database. This command provides:

A database must be configured before you can enable class scheduling with the enable command. If a database does not exist when you enter the class_admin command, the command will invoke an interactive session and prompt you to automatically configure a database. If a script invokes the class_admin command, it uses the system defaults to configure the database.

The following example shows an interactive configuration session using class_admin. In the actual output, the lines will be formatted to fit in 80 columns.

# /usr/sbin/class_admin
                    Class Scheduler Administration
 
configure:
 
Shall processes that have not been explicitly
assigned to a defined class be assigned to a
'default' class?  Enter (yes/no) [no]: yes
 
Enforce class scheduling when the CPU is otherwise
idle? (yes/no) [no]: yes
 
How often do you want the system to reset class usage?
Enter number of seconds (1): 2
class>

The configuration values have the following effect:

In the example, a default class was created and all current processes were assigned to that class. Class scheduling will be enforced even when the CPU is idle and class usage will be reset every five seconds.

To review the current configuration, enter the show command:

class> show
Configuration:
 -Processes not explicitly defined in the database are
  class scheduled.
 -If the processor has some idle time, class scheduled
  processes are not allowed to exceed their cpu percentage.
 -The class scheduler will check class CPU usage every 2
  seconds.
 
Class scheduler status: disabled  current database: /etc/class
 
Classes:
 
 default targeted at 100%:
    class members:
    Every one not listed below
 
 

The next step in the process is to create classes and populate the classes with system processes such as tasks, daemons, or user accounts by using the appropriate identifiers such as UID or SESS.

13.2.2.4    Creating and Managing Classes

When the database is configured, you can administer classes as follows:

Some of these options are described briefly in the following sections. For detailed descriptions of command options, see the online help and reference pages.

13.2.2.4.1    Creating a Class

To create a class, either use the command-mode or enter an interactive session as follows:

# class_admin
class> create high_users 50

The command-mode version is entered as follows:

# class_admin create batch_jobs 10
batch_jobs created at 10% cpu usage
 
 
changes saved

The first command creates a class named high_users and assigns a CPU usage restriction of 50 percent. The second command creates a class named batch_jobs and assigns a CPU usage restriction of 10 percent. In command mode, the changes are automatically saved to the database in /etc/class. When making changes to classes interactively, use the save command to commit changes to the database. If you attempt to end the session with the quit command and there are unsaved changes, you will be prompted to save or discard the changes before quitting the interactive session as follows:

class> quit
Class scheduler database modified.
Save changes? (yes/no) [yes]:yes
 
changes saved
 
 

13.2.2.4.2    Managing Identifier Types Within Classes

Unique system-assigned identifiers that the class scheduler recognizes (such as the PID, GID, or UID) identify which processes are members of a specific class. After you have created classes, you can add UIDs and GIDs or processes to one or more classes by using the add command. You must specify the type of identifier (ID) used and enter one or more unique identifiers. UIDs and GIDs can be determined from the /etc/passwd and /etc/group files. Alternatively, you can use the graphical interface Account Manager (dxaccounts) to display UID and Group information.

Process identifiers can be obtained from system files or by using a command such as ps. With the ps command, you can determine the values of PID, PGID, and SESS. Enter the following command to display the PID for every process running on the system:

# /sbin/ps aj
 
 
USER   PID PPID  PGID  SESS JOBC S    TTY          TIME COMMAND
walt  5176 5162  5176  2908   1  S    ttyp1    0:01.30 -sh (csh)
root 12603 5176 12603  2908   1  R  + ttyp1    0:00.05 ps aj

See ps(1) for more information and a definitive list of the process data items displayed when you use this command.

The following identifiers are supported:

gid

A group identification number from the /etc/group file. For example, if you are adding members to a class, using this number will add all the users that are assigned to the group.

uid

A user identification number from the /etc/passwd file. For example, if you are adding members to a class, this number will add only the specific user to which the UID is assigned.

pgrp

A process group identifier. In the output from the ps aj command, see the entries under the PGID table heading in the previous example.

session

A session identifier. In the output from the ps aj command, see the entries under the SESS table heading in the previous example.

pid

The process identifier. In the output from the ps aj command, see the entries under the PID table heading in the previous example.

It is most likely that you will use types uid and gid in your established classes, as these values will persist across a reboot or when class scheduling is stopped and restarted. You can use the account management tools, such as dxaccounts or the Accounts option of the SysMan Menu, to list UIDs and GIDs for users and groups. The identifiers associated with types pgrp, session, and pid are temporary, and will not exist on reboot or when a process terminates.

13.2.2.4.3    Enabling the Class Scheduler

To enable the class scheduler daemon, enter the following command:

# class_admin enable
Class scheduling enabled and daemon \
/usr/sbin/class_daemon started.

To disable the daemon, enter the following command:

# class_admin disable
Class scheduling disabled.

13.2.2.4.4    Adding Members to a Class

To add a process to a class, enter the add command as shown in the following interactive mode example:

class> add batch_jobs uid 234 457 235
 
 

You must use one of the unique identifiers previously specified, and you cannot add the same identifier to a class more than once. The same procedure can be performed in command mode or from a script as follows:

# class_admin add batch_jobs uid 234 457 235
uid 234 457 235 added to high_users

In command mode, additions to a class are automatically saved to the /etc/class database.

13.2.2.4.5    Deleting Members From a Class

To delete one or more processes from a class, enter the delete command in interactive or command mode. For example:

class> delete high_users uid 11
uid 11 deleted from high_users

This example deletes the single UID number 11 from class high_users.

13.2.2.4.6    Other Class Management Options

See class_admin(8) for information on the following options:

13.2.2.5    Using the runclass Command

Once you have established scheduler classes and enabled class scheduling, you can use the runclass command to execute a command in a particular class. When you use the runclass command as root user (superuser), your processes have unrestricted access to CPU resources even when assigned to an existing class. By default, root processes are never restricted. This ensures that no user process can lock up resources needed by the root account. If you need to test a class scheduler configuration, ensure that you log in and create processes using a nonprivileged user account. You might want to set up dummy user accounts to perform such testing.

The following command uses the runclass command to open a terminal window and assign it to the previously created high_users class:

# runclass high_users xterm

The following command shows that the pgrp number for the terminal process is now identified as a member of that class:

# class_admin show
.
.
.
class members:
pgrp 24330     pgrp 24351     pgrp 24373

In this example, the identifier for the xterm process is added to the class. You can use the following command to view the running process:

# ps agx | grep xterm

See runclass(1) for more information.

13.2.2.6    Using the Class Scheduling Graphical Interface

The class scheduler can be launched from the SysMan menu by selecting the Class Scheduling option from the Monitoring and Tuning tasks. Alternatively, you can launch it from the Common Desktop Environment (CDE) Application Manager.

As for the command-line method of using the class scheduler described in preceding sections, the steps involved in initial configuration are as follows:

  1. Plan your classes and the processes, users, or groups that will be in each class.

  2. Configure and name a database by creating classes and adding them to the database.

  3. Define the new database as the current database.

  4. Start the class scheduling daemon.

You can complete these steps by using the SysMan Menu Class Scheduling main menu option, where the following three suboptions are available:

Configure Class Scheduler

This is the main option that you use to configure and initialize class scheduling. When you select this option, a window is displayed: Configure Class Scheduler on hostname. From here you can select one of the following options:

The New... option is the main option and the one most frequently used. It is described in detail in Section 13.2.2.7. The Modify... option provides an identical interface, which allows you to change existing classes and databases.

The remaining menu options require only a confirmation and do not involve extensive data entry. For example, if you want to delete a database, you will only be prompted to confirm that the database is to be destroyed.

[Re]Start Class Scheduler

Use this option to start the class scheduling daemon, or restart it if it was stopped. You will be prompted to confirm your selection.

Stop Class Scheduler

Use this option to stop the class scheduling daemon. You will be prompted to confirm your selection.

See the System Administration manual for information on running the SysMan Menu. Section 13.2.2.6 describes how you use the graphical interface. See the online help for additional information on valid data entries.

13.2.2.7    Creating or Modifying a Database

When you select the New... or Modify... options, a screen is displayed titled Configure Class Scheduler: Create/Modify Scheduling Database. To create a new database, follow these steps:

  1. In the Name: field, type the name of the database that you want to create. The name should reflect the function of the database, so that you can easily recognize it when it is displayed in a list of many options. For example, served_applications.

  2. From the option list titled Available Scheduled Classes, you can select any existing classes. If you are setting up the first database, no classes will be listed and only the New.. option will be available for selection.

  3. To create a new class, press the New... button to display the window titled Create a new class. In this window, you complete the following steps:

  4. When classes are created, they appear as entries in the optional list of Available Scheduling Classes. Apart from the class name, the CPU time percentage allocation and member and type are also displayed. You can now select classes to add to the database as follows:

  5. When all required classes are selected, press the OK button to create the new database. The new database will be added to the list of Available Scheduling Databases.

You also use the Configure Class Scheduler: Create/Modify Scheduling Database window to perform maintenance and administrative operations on classes as follows:

To begin using the newly created database, follow these steps:

  1. If the window titled Configure Class Scheduler on hostname is not already displayed, invoke the SysMan Menu and select the Configure Class Scheduler option.

  2. Highlight the required database by clicking on it, then press the Make Current... button. You will be prompted to confirm or cancel your choice.

  3. Press the OK button to return to the SysMan Menu, Class Scheduling options, and select the option titled [Re]Start Class Scheduler. You will be prompted to confirm your choice.

On completing these steps, the class scheduling daemon starts and uses the scheduling database that you specified. To verify and monitor that the database is working as anticipated, use the show command at the terminal command line. For example, to view scheduling statistics, enter the following command:

# class_admin stats
 
Class scheduler status: enabled \
current database: /etc/.cl_lab1
 
class name     target percentage  actual percentage
prio-tasks-lab        10                  10

You might need to spend some time monitoring tasks and system performance, tuning your classes to obtain the required results.

13.2.3    Prioritizing Jobs

You can prioritize jobs so that important applications are run first. Use the nice command to specify the priority for a command. Use the renice command to change the priority of a running process.

See nice(1) and renice(8) for more information.

13.2.4    Scheduling Jobs at Offpeak Hours

You can schedule jobs so that they run at offpeak hours (use the at and cron commands) or when the load level permits (use the batch command). This can relieve the load on the CPU and the memory and disk I/O subsystems.

See at(1) and cron(8) for more information.

13.2.5    Stopping the advfsd Daemon

The advfsd daemon allows Simple Network Management Protocol (SNMP) clients such as Netview to request AdvFS file system information. If you are not using the AdvFS graphical user interface (GUI), you can free CPU resources and prevent the advfsd daemon from periodically scanning disks by stopping the advfsd daemon.

To prevent the advfsd daemon from starting at boot time, rename /sbin/rc3.d/S53advfsd to /sbin/rc3.d/T53advfsd.

To immediately stop the daemon, enter the following command:

# /sbin/init.d/advfsd stop

13.2.6    Using Hardware RAID to Relieve the CPU of I/O Overhead

RAID controllers can relieve the CPU of the disk I/O overhead, in addition to providing many disk I/O performance-enhancing features. See Section 9.4 for more information about hardware RAID.