Linux performance Analysis--top__linux

Source: Internet
Author: User
Tags memory usage safe mode cpu usage


Top

The top command is one of the most popular performance tools. Most system administrators run top to view the operation of Linux and UNIX systems. The top utility provides an ideal way to monitor process and overall Linux performance. It's more accurate to call Linux processes tasks, but in this chapter we call them processes, because that's what the tool calls them. 1 normal users and root users can run top. Figure 3-1 shows the typical top output of an idle system.

Figure 3-1 Top output

Top display has two parts. Approximately the top One-third shows the overall information about Linux, the rest of the process information. If the extension window displays more processes and fills the entire screen.

More comprehensive Linux information can be obtained by using a few commands other than top. However, it is ideal to display all the information on one screen with a single command. The first line shows the load average for the last 1 minutes, 5 minutes, and 15 minutes. The load average indicates how many processes are running on the CPU or waiting to be run. The uptime command can also be used to display load averages. The next step is process information, followed by CPU, memory, and swap areas. The memory and swap area information is similar to the free command output. The next issue after we determine the memory and CPU usage is which processes are using it.

Most process information can also be obtained through the PS command, but top provides a more readable format. The most useful is the H that provides help, which lists the other interactive commands for top. 3.1.1 Add and remove fields

Fields can be added or removed from the display. The process output can be sorted by CPU, memory, or other metrics. This is an ideal way to see what processes are robbing memory. The top syntax and interactive options for each Linux release version are different, and the Help commands can quickly list what commands are available. There are many interactive options available, and users should spend some time experimenting with them.

Figure 3-2 shows the help screen for Red Hat Enterprise Linux ES Release 3.

Figure 3-2 Top's help screen

The f command is used to add or remove fields from the top output. Figure 3-3 is a help screen for red Hat Enterprise Linux ES Release 3, showing what fields can be added.

Figure 3-3 Top Add/Remove field screen

Figure 3-4 shows a help screen for the SuSE Linux 9.0 top, which can be seen as very different from the commands they provide.

Figure 3-4 SUSE Top's help screen 3.1.2 Interpreting output

Let's look at the meaning of top information, taking the following output from top as an example:

The first line of the top output shows the load average information:

This output is similar to the output of the uptime. You can see how long Linux has elapsed, the current time and the number of users, and the 1-minute, 5-minute, and 15-minute load averages. Next, the process summary is displayed:

We see a total of 73 processes, 72 of which are hibernating, a process running, no rigid processes, or processes that are stopped. When a process exits and its parent process waits for it without a wait (2) or waitpid (2) function, it becomes a rigid process. This is usually caused by the parent process exiting before its child process. Unlike items in the process table, a rigid process does not use resources. A stopped process is a process that has been sent a stop signal to it. For more information, refer to the signal (7) man page.

Next is CPU information:

The CPU line describes how CPUs use their CPU cycles. The top command reports the percentage of CPU time spent in user or kernel mode, running a good process, and in idle state. The iowait column shows the percentage of time that the processor waits for I/O to complete when no process is running on the CPU. IRQ and SOFTIRQ columns represent the time it takes to process hardware and software interrupts. The Linux kernel earlier than version 2.6 does not report IRQ, SOFTIRQ, and iowait.

Next is the memory information:

The first three metrics provide a summary of memory usage, listing total available memory, used memory, and free memory, all of which determine whether the required information is sufficient for Linux memory.

The next five indicators identify how the used memory is allocated. The SHRD field shows the shared memory usage, and the buff is the memory used for buffering. The memory allocated to the kernel or user process can be in three different states: active, inactive, dirty (inactive dirty), and inactive (inactive clean). The activity is represented in the top with AOTV, indicating that the memory was recently used. Inactive dirty is represented in top with In_d, indicating that the memory has not been used recently and can be recycled. To reclaim memory, its contents must be written to disk, which is named "Clean" or the fourth temporary state of memory. Once cleaned, inactive dirty memory becomes inactive clean memory, expressed in In_c in top. Understanding Virtual Memory in Red Hat Enterprise Linux 3, co-authored by Norm Murray and Neil Horman, is an excellent reference book for http:people.redhat.com /nhorman/papers/rhel3_vm.pdf.

Next is the Swap area information:

The AV field is the total number of swap areas available, followed by the amount used and the number of free, and finally the amount of memory the kernel uses to cache.

The remainder of the top display is process information:

Top shows as many processes as possible that fit the screen. The description of the field description is provided in the top (1) man page. Table 3-1 provides a summary of these fields.

Table 3-1 Top Process Field

Field

Description

Pid

Process ID Number

USER

User name of the process owner

Pri

Priority of the process

SIZE

Process size, including its code, stack, and data region, in kilobytes

Rss

Total amount of memory used by the process, in kilobytes

SHARE

Amount of shared memory used by the process

STAT

The state of the process, usually r represents the run, and S indicates hibernation

%cpu

The percentage of CPU used by this process since the most recent screen update

%mem

Percent of memory used by this process

Time

The amount of CPU time used by this process since the process started

Cpu

CPU of the most recent execution process

COMMAND

The command being executed

3.1.3 Save Custom

A very good top feature is to save the current configuration. You can use interactive command s to change the display arbitrarily, and then press W to save the view.

Top writes A. toprc file in the user's home directory to save the configuration so that the next time the user launches the top, the same display option is used.

Top also looks for the default profile/ETC/TOPRC. This is a global configuration file that the top will read when any user runs the utility. This file allows top to run in safe mode, or it can set the refresh latency. Safe mode prevents non-root users from logging off or changing the normal value of a process, and also prevents non-root users from changing the top refresh values. A/ETC/TOPRC sample file for Red Hat Enterprise Linux ES Release 3 looks like this:

s represents safe Mode, 3 defines a three-second refresh interval. Other release versions may have different/ETC/TOPRC formats. The logoff process is a very useful feature. If the user has a runaway process, the top command makes it easy to find and unregister it by running top, displaying all of the user's processes through the U command, and then unregistering it with K. Top is not just a good performance monitoring tool, it can also be used to improve performance by logging off those processes that are causing the problem. 3.1.4 Batch processing mode

Top can also be run in batch mode. Try running the following command:

-N 1 tells top to show only one iteration, and the-B option is to be exported as text that is appropriate for writing to a file or directed to another program (for example, less). A command that resembles the following two lines of script can successfully complete a cron job:

It can be added to the crontab and the output is collected every 15 minutes.

Batch processing allows all tasks to be done easily without user intervention. All processes are listed and the output is not refreshed every 5 seconds. If a. TOPRC configuration file exists in the user's home directory, it is used to format the display. The following is the output that runs the top batch mode on a multiple-CPU Linux server. Note that there are no 258 processes showing the top output.

Now the reader may understand why top is so popular. The interactive nature of top and the ability to easily customize the output make it an excellent tool for diagnosing problems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.