Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux simple command solves system performance problem

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "Linux simple commands to solve system performance problems", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "Linux simple commands to solve system performance problems"!

1. Top

For many administrators, what you learn is the TOP command, which shows all the kernel tasks currently running and provides some statistical reports on the status of the host. By default, the TOP command automatically updates this data every five minutes (this update interval is configurable).

The functionality of the TOP command is incredibly rich (it is estimated that few people have used more than half of the functionality). Generally speaking, you start with the'h' key, which is' help''(the documentation is also excellent). Help parameters can quickly show what you can add and subtract from it, and you can also change the sort. You can also use k to end a process or r to mark a particular process.

The Top command shows the uptime of the day, the system load, the number of processors, memory usage, and which processes used most of the CPU resources (including a great deal of information about each process, such as online users and commands in progress, and so on).

II. Vmstat

The Vmstat command gives you a snapshot of current CPU, IO, process, and memory usage. Like the TOP command, it automatically refreshes dynamically and can be executed with the following command:

$vmstat 10

In this case, delay refers to the time in seconds between two refreshes, and here it 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 you execute it). This continuous output is sometimes used to import into a file to analyze performance trends, but we will find a better way to do this, as described later in the article.

The * * column shows the processor, the r column is the standby processor, and the b column is the dormant processor. If you see a lot of standby processors here, you may be experiencing a performance bottleneck somewhere. The second column shows memory: virtual, free, buffered and cached memory. The third column shows the swap storage and how much memory is swapped with the disk. The fourth column is the Iamp O information, which shows the block data information received and sent by the block service.

The * two columns show information about the system and CPU. The system column shows the number of conflicts and swaps per second. The CPU column shows particularly useful information. Each segment shows a percentage of CPU time. These are as follows:

US: time spent running user tasks and code

SY: the time it takes to run kernel or system code

ID: idle time

WA: time spent waiting for IO

ST: time taken by the virtual machine

The VMSTAT command is good at querying CPU usage, although keeping in mind that each parameter depends largely on continuous monitoring, because with a short look at CPU, you may not know what the real problem with CPU is. You need to look at long-term running trends to get an exact CPU performance information.

III. Iostat

The next order we're going to talk about is IOSTAT. The IOSTAT command (provided by the SYSSTAT package on UBUNTU, Red Hat, and FEDORA systems) provides three reports: CPU usage, device usage, and network file system usage. If you run the command without any parameters, it displays all three reports, and you can display one of them separately by adding the parameters-c,-d, and-h.

In the figure above you can see two of these reports, * CPU usage, which classifies the CPU consumed by each process as a percentage. You can see the user process, system process, iowait and idle time and other information.

The second report is on device utilization, showing each device installed on the host and some useful information, such as transfers per second, block reads and writes, and allows you to mark devices with performance problems. You can display statistics in kilobytes or megabytes by adding-k or-m parameters, rather than in blocks, which will be easier to read and understand in some cases.

* A report without screenshots displays information similar to the device usage described above, except that the object is changed from an attached device to a mounted network file system.

IV. Free

The next command, free, displays the statistics of main memory and swapped memory.

You can display the total memory by adding the-t parameter, or by adding the-b and-m parameters in bytes (the default is in kilobytes).

The FREE command can also run continuously refreshed at intervals by using the-s argument:

$free-s 5

This command runs the FREE command and prints the result in a refresh every 5 seconds.

5. Sar

Like many other tools we have seen, we can use the sar command to collect, view, and record server performance data. It is more powerful than any similar tool we have seen and can collect and display data over long periods of time. On Red Hat and UBUNTU, it is installed through the SYSSTAT package. Let's start by running the SAR command without adding any parameters:

$sar

From here we can see the basic output of the sar command, including CPU statistics (data every 10 minutes and * average data). This information is extracted from a daily statistics file that collects information on a 24-hour basis (this file is stored in the directory / var/log/sa/ and is ordered to be in a format like saxx, where xx represents the date on which the data was collected). In addition, it also collects statistics about memory, devices, networks, etc. (for example, you can view block device statistics by adding the-b parameter,-n view network data, and-r parameters look at memory usage). You can also use the-A parameter to view all 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 effect, you need to use the parameter-o and a file name, the time interval to run the command (remember that collecting data will lead to poor performance, so * * make sure this interval is not too short) and the number of cycles-the number of intervals you want to record. If you do not enter the number of loops, the sar command runs forever, for example:

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

Here we will collect all the data (- A), record it in the file / var/log/sar/sar.log, collect it every 600 seconds (or 5 minutes), and run continuously in the background. If we want to display this data next, we can use the sar command with the-f argument, for example:

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

This is a very basic introduction to sar commands. You can also get a lot of useful data with the sar command, which makes it more convenient and efficient to view the performance of the host. I suggest you take a look at the documentation for the sar command to get a more detailed way to get the data you need.

At this point, I believe you have a deeper understanding of "Linux simple commands to solve system performance problems". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report