Five big Linux simple commands to resolve system performance issues

Source: Internet
Author: User

Five big Linux simple commands to resolve system performance issues 2010-12-17 10:07 James Turnbull techtarget Chinafont Size:T | T

Managing the performance of a Linux host often looks like a magic trick. Many administrators often simplify processing when encountering performance problems, relying on hardware upgrades, larger memory, and stronger CPUs to solve problems. In fact, with some simple commands, you can find many details of managing hosts and can quickly and easily resolve performance issues.

AD:2014WOT Global Software Technology Summit Beijing Station course video release

Managing the performance of a Linux host often looks like a magic trick. Many administrators often simplify processing when encountering performance problems, relying on hardware upgrades, larger memory, and stronger CPUs to solve problems. In fact, with some simple Linux commands, you can discover the details of many management hosts and solve performance problems quickly and easily.

First, top

For many administrators, the latest learning is the top command, which shows all the kernel tasks that are currently running, and provides some statistical reports of host status. By default, the top command automatically updates this data every five minutes (this update interval is configurable).

The top command is incredibly versatile (it is estimated that very few people have used more than half of the functionality). In general, you will start with the ' H ' key, which is ' help ' (the documentation is wonderful too). Help parameters can quickly show what you can add and subtract from, and you can change the sort. You can also use K to end a process or to annotate a particular process with R.

The top command shows the day's uptime, system load, number of processors, memory usage, and which processes use most of the CPU resources (including a large amount of information about each process, such as online users and the commands being executed).

Second, Vmstat

The Vmstat command gives you a snapshot of the current CPU, IO, process, and memory usage. As with the top command, it is automatically refreshed dynamically and can be executed with the following command:

$ vmstat 10

Here the delay is the time of two refresh interval in seconds, here is 10 seconds. The Vmstat command will refresh the results of the check on the screen until you end it with the ctrl-c command (or you can set a limit when executing). The results of this continuous output are sometimes used to import into files to analyze performance trends, but we will find a better way to do this, as explained later in this article.

The first column shows the processor, the R column is the standby processor, and the B column is the processor that sleeps. If you see a number of standby processors here, you may be experiencing a performance bottleneck somewhere. The second column shows the memory: virtual, idle, buffered, and cached memory. The third column shows the swap storage and how much is present and the disk is swapped. The fourth column is the I/O information, which shows the block data information received and sent by the block service.

The last two columns show system-and CPU-related information. The system column shows the number of conflicts and the exchange per second. The CPU column is a particularly useful information display. Each column shows a percentage of the CPU time. The following are the breakdown:

US: Time spent running user tasks and code

SY: Time spent running the kernel or system code

ID: Idle Time

WA: Time spent waiting for IO

ST: The time the virtual machine takes

The Vmstat command is good at querying CPU usage, although it is important to remember that each parameter depends primarily on continuous monitoring because you may not be able to tell the real problem of the CPU by observing the CPU for a short time. You need to look at the long run trend to get an exact CPU performance information.

Third, Iostat

The next command we're going to talk about is iostat. The Iostat command (which is provided by the Sysstat package in Ubuntu, Red Hat, and Fedora Systems) provides three reports: CPU utilization, device utilization, and network file system utilization. If you run the command without any parameters, it will show all three reports, and you can display one of them individually by adding parameters-C,-D, and-H.

In the above figure you can see two of them, the first of which is CPU utilization, which lists the CPU consumed by each process as a percentage. You can see information such as user processes, system processes, iowait, and idle time.

The second report is about device usage, shows each device installed on that host, and some useful information, such as the number of transmissions per second, data block reads and writes, and allows you to mark devices with performance problems. You can display statistics in kilobytes or megabytes by adding the-K or-m parameters instead of data blocks, which in some cases is easier to read and understand.

The last report, no, the information displayed is a bit similar to the device usage described above, except that the object is replaced by the attached device with the attached network file system.

Iv. Free

The next command, free, displays the statistics for both main memory and swap memory.

You can display the total memory by adding the-t parameter, or by adding the-B parameter and the-m parameter to the number of bytes (by default, in kilobytes).

The free command can also be run continuously at a certain interval by using the-s parameter:

$ free-s 5

This command runs the free command in a refreshed manner every 5 seconds and outputs the result.

V. SAR

Like many other tools we've seen, we can use SAR commands to collect, view, and record server performance data. It is more powerful than any similar tool we have ever seen and can collect and display data for long periods of time. On Red Hat and Ubuntu, it is installed through the Sysstat package. Let's start by never adding any parameters to run the SAR command:

$ SAR

From here we can see the basic output information of the SAR command, including CPU statistics (data every 10 minutes and the last average data). This information is fetched from a daily statistical file that collects information in 24 hours (this file is stored in the directory/var/log/sa/, and is ordered to be in a format such as Saxx, where xx represents the date the data was collected). It also collects statistics about memory, devices, networks, and so on (for example, by adding the-B parameter to view the block device statistics, the-N-View network data, the-r parameter to see memory usage). You can also use the-a parameter to view all the collected data.

You can also run the SAR command for a long time and then import the output data into a file to collect data. To achieve this, you need to use the parameter-o and a file name to run the time interval of the command (remember that collecting data can cause poor performance, so it's best to ensure that this interval is not too short) and the number of cycles-the number of intervals you want to log. If you do not enter the number of loops, the SAR command will continue to run, for example:

$ sar-a-o/var/log/sar/sar.log >/dev/null 2>&1 &

Here we will collect all the data (-a), log it to the file/var/log/sar/sar.log, collect it every 600 seconds (or 5 minutes), and continue to run in the background. If we want to show this data next, we can add the-f parameter with the SAR command, for example:

$ sar-a-f/var/log/sar/sar.log

This is a very basic introduction to the SAR command. With the SAR command, many useful data can be obtained, which makes it more convenient and effective to view the host's performance. I suggest you look at the documentation for the SAR command to get a more detailed approach to getting the data you need.

In this article, we've seen 5 basic command tools for managing and viewing performance status on a Linux host. Besides, it's also worthwhile to take a look at some other tools, such as Munin and collected, which not only collect data about performance, but also view applications and services, including using your own plugins. These tools support the addition of graphical input, which allows you to view your data more visually.

"Editor's recommendation"

Five big Linux simple commands to resolve system performance issues

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.