preface

This article covers common Linux commands for performing performance checks, common Linux system-level tuning methods, and common interview questions.

1. uptime

$uptime 23:51:26 up 21:31, 1 user, load average: 30.02, 26.43, 19.0212Copy the code

This command can roughly see the overall load of the computer, the number after the load average indicates the average load of the computer in 1min, 5min and 15min respectively.

2. dmesg | tail

$dmesg | tail [1880957.563150] perl invoked oom - killer: gfp_mask = 0 x280da, order = 0, oom_score_adj = 0 [...]. [1880957.563400] Out of memory: Kill process 18694 (perl) score 246 or sacrifice child [1880957.563408] Killed process 18694 (perl) total-VM :1972392kB, Anon - RSS: 1953348 KB, file - RSS: 0 KB [2320864.954447] TCP: Possible SYN flooding on port 7001. Dropping request. Check SNMP counters.123456Copy the code

Prints the contents of the kernel ring cache, which can be used to see some errors.

In the example above, process 18694 was killed due to memory overruns and the TCP request was discarded. Using DMESG, you can quickly determine whether there are problems that cause system performance exceptions.

3. vmstat 1

$ vmstat 1 procs ---------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so  bi bo in cs us sy id wa st 34 0 0 200889792 73708 591828 0 0 0 5 6 10 96 1 3 0 0 32 0 0 200889920 73708 591860 0 0 0 592 13284 4282 98 11 00 32 00 200890112 73708 591860 00 0 9501 2154 99 1 00 0 32 00 200889568 73712 591856 00 0 48 11900 2459 99 00 00 32 00 200890208 73712 591860 00 0 15898 4840 98 11 00Copy the code

Prints process, memory, swap partition, IO, AND CPU statistics.

The format of vmstat is as follows:

vmstat [options] [delay [count]]
Copy the code

The first output of vmstat indicates the average value from startup to vmstat running. The rest of the output is the average value within the specified time interval. In the example above, the value of delay is set to 1. Except for the first time, the rest of the output is calculated once every second.

$ vmstat 10 3 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 2527112 1086888 13720228 0 0 1 14 2 1 1 1 99 0 0 0 0 0 2527156 1086888 13719856 0 00 104 3003 4901 00 990 00 0 2526412 1086888 13719904 00 0 10 3345 4870 01 990 0123456Copy the code

In the example above, delay is set to 10 and count is set to 3, indicating the average value of each line printed for 10 seconds, only 3 times.

Columns to check:

1.r

Indicates the number of processes that are running or waiting for CPU scheduling. Since this column contains no I/O statistics, it can be used to detect whether the CPU is saturated. If the number in column R is greater than the number of CPU cores, the CPU is saturated

2.free

The remaining memory

3.si, so

Number of swap partitions in and out. If the number of swap partitions in and out is greater than 0, the memory is insufficient

4.us, sy, id, wa

CPU statistics, indicating user time, System time(kernel), IDLE, and WAIT I/O. The I/O processing time is included in system Time. Therefore, if the system time exceeds 20%, I/O bottlenecks or exceptions may exist

4. mpstat -P ALL 1

$mpstat -p ALL Linux 3.10.0-229.el7.x86_64 (localhost. Localdomain) 05/30/2018 _x86_64_ (16 CPU) 04:03:55 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle 04:03:55 PM all 3.67 0.00 0.61 0.71 0.00 0.00 0.00 0.00 0.00 0.00 95.02 04:03:55 PM 0 3.52 0.00 0.57 0.76 0.00 0.00 0.00 0.00 0.00 95.15 04:03:55 PM 1 3.83 0.00 0.61 0.71 0.00 0.00 0.00 0.00 0.00 0.00 94.85 04:03:55 PM 2 3.80 0.00 0.61 0.60 0.00 0.00 0.00 0.00 0.00 94.99 04:03:55 PM 3 3.68 0.00 0.58 0.60 0.00 0.00 0.00 0.00 95.13 04:03:55 PM 4 3.54 0.00 0.57 0.60 0.00 0.00 0.00 0.00 0.00 95.30 [...]Copy the code

This command is used to print the statistics of each CPU every second to check whether the CPU scheduling is uniform.

5. pidstat 1

$pidstat 1 Linux 3.13.0-49-generic (titanclusters- XXXXX) 07/14/2015_x86_64_ (32 CPU) 07:41:02 PM UID PID %usr %system %guest %CPU CPU Command 07:41:03 PM 0 9 0.00 0.94 0.00 0.94 1 rcuos/0 07:41:03 PM 0 4214 5.66 5.66 0.00 11.32 15 Mesos-slave 07:41:03 PM 0 4354 0.94 0.94 0.00 1.89 8 Java 07:41:03 PM 0 6521 1596.23 1.89 0.00 1598.11 27 Java 07:41:03 PM 0 4354 0.94 0.94 0.00 1.89 8 Java 07:41:03 PM 0 6521 1596.23 1.89 0.00 1598.11 27 Java 07:41:03 PM 0 6564 1571.70 7.55 0.00 1579.25 28 Java 07:41:03 PM 60004 60154 0.94 4.72 0.00 5.66 9 pidstat 07:41:03 PM UID PID %usr %system % Guest %CPU CPU Command 07:41:04 PM 0 4214 6.00 2.00 0.00 8.00 15 mesos-slave 07:41:04 PM 0 6521 1590.00 1.00 0.00 1591.00 27 Java 07:41:04 PM 0 6564 1573.00 10.00 0.00 1583.00 28 Java 07:41:04 PM 108 6718 1.00 0.00 1.00 0 snmp-pass 07:41:04 PM 60004 60154 1.00 4.00 0.00 5.00 9 pidstatCopy the code

This command displays the CPU usage of each process, similar to that displayed in the top command. The advantage of Pidstat is that it can scroll to print the running status of the process, unlike top, which clears the screen. In the example above, the CPU utilization of the two Java processes in %CPU is 1590% and 1573%, respectively, indicating that Java processes are using 16 cpus.

6. iostat -xz 1

Similar to vmstat, the first output is sampled data from the time of system startup to statistics.

$iostat -xz 1 Linux 3.13.0-49-generic (titanclusters-xxxxx) 07/14/2015_x86_64_ (32 CPU) AVG-CPU: %user %nice % System %iowait %steal %idle 73.96 0.00 3.73 0.03 0.06 22.21 Device: RRQM /s WRQM/S r/ S w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await SVCTM %util xvda 0.00 0.23 0.21 0.18 4.52 2.08 34.37 0.00 9.98 13.80 5.42 2.44 0.09 XVDB 0.01 0.00 1.02 8.94 127.97 598.53 145.79 0.00 0.43 1.78 0.28 0.25 0.25 XVDC 0.01 0.00 1.02 8.86 127.79 595.94 146.50 0.00 0.45 1.82 0.30 0.27 0.26 dm-0 0.00 0.00 0.69 2.32 10.47 31.69 28.01 0.01 3.23 0.71 3.98 0.13 0.04 dm-1 0.00 0.00 0.00 0.94 0.01 3.78 8.00 0.33 345.84 0.04 346.81 0.01 0.00 dm-2 0.00 0.00 0.09 0.07 1.35 0.36 22.50 0.00 2.55 0.23 5.62 1.78 0.03 [...]Copy the code

Check the column

1. R /s, w/s, rkB/s, and wkB/s: indicates the number of reads, writes, read Kbytes, and write Kbytes sent to the I/O device per second

2. Await, represents the average I/O time that the application is queued and served. A value greater than expected indicates that the I/O device is in the saturation state or is abnormal

3. Avgqu-sz: indicates the average time for sending requests to an I/O device. If the value is greater than 1, the I/O device may be saturated

4.%util, device utilization per second; If the usage exceeds 60%, the device performance is abnormal

7. free -m

$ free -m
             total       used       free     shared    buffers     cached
Mem:        245998      24545     221453         83         59        541
-/+ buffers/cache:      23944     222053
Swap:            0          0          012345
Copy the code

Columns to check:

1.buffers

For the buffer cache, used for block device I/O

2.cached

For the page cache, used by file systems

If buffers and cached are close to 0, the I/O usage is too high and the system has performance problems. In Linux, free memory is used as the cache. If an application needs to allocate memory, the system can quickly reclaim the memory used by the cache. Therefore, free memory contains the memory used by the cache.

8. sar -n DEV 1

SAR stands for System Activity Reporter, System Activity status report.

– n {keyword [,…]. | ALL}, used to report network statistics. Keyword can be one or more of the following: DEV, EDEV, NFS, NFSD, SOCK, IP, EIP, ICMP, EICMP, TCP, ETCP, UDP, SOCK6, IP6, EIP6, ICMP6, EICMP6 and UDP6.

-n DEV 1: Collects network usage statistics every second.

-n EDEV 1: Collects incorrect network information every second.

$SAR -n DEV 1 Linux 3.10.0-222.el7.x86_64 (localhost. Localdomain) 05/31/2018 _x86_64_ (16 CPU) 03:54:57 PM IFACE RXPCK /s TXPCK/S rxkB/s txkB/ S RXCMP/S TXCMP/S RXMCST /s 03:54:58pm ens32 3286.00 7207.00 283.34 18333.90 0.00 0.00 0.00 03:54:58 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 03:54:58 PM vethe915e51 0.00 0.00 0.00 0.00 0.00 0.00 03:54:58 PM vethe915e51 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 03:54:58pm IFACE RXPCK /s TXPCK /s rxkB/s txkB/s RXCMP /s TXCMP /s RXMCST /s 03:54:59 PM ens32 3304.00 7362.00 276.89 18898.51 0.00 0.00 0.00 03:54:59 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 03:54:59 PM vethe915e51 0.00 0.00 0.00 0.00 0.00 0.00 03:54:59 PM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00Copy the code

1.IFACE, the name of the network interface

2. RXPCK /s: the number of packets received per second

3. TXPCK /s, the number of packets transmitted per second; (transmit packages)

4. RxkB /s, kilobytes received per second

5. TxkB /s, the number of kilobytes sent per second

6. RXCMP /s: the number of compressed packets received per second

7. TXCMP /s, the number of compressed packets sent per second

8. RXMCST /s, the number of group packets received per second

9. sar -n TCP,ETCP 1

This command can be used to roughly determine the network throughput, such as the number of network connections initiated and the number of network connections received.

1.TCP, reports statistics on TCPv4 network traffic

2.ETCP, reports statistics about TCPv4 network errors

$SAR -n TCP,ETCP 1 Linux 3.10.0-514.26.2.el7.x86_64 (Aushop) 05/31/2018 _x86_64_ (2 CPU) 04:16:27 PM active/s passive/s Iseg /s oseg/s 04:16:44pm 0.00 2.00 15.00 13.00 04:16:45pm 0.00 3.00 126.00 203.00 04:16:46pm 0.00 0.00 99.00 99.00 04:16:47 PM 0.00 0.00 18.00 9.00 04:16:48 PM 0.00 0.00 5.00 6.00 04:16:49 PM 0.00 0.00 1.00 1.00 04:16:50 PM 0.00 1.00 4.00 4.00 04:16:51pm 0.00 3.00 171.00 243.00Copy the code

Test columns:

1.active/s

Number of locally-initiated TCP connections per second (e.g., via connect()

2.passive/s

Remotely initiated TCP connections per second (e.g., via accept()

3.retrans/s

Transmits TCP retransmits per second Number of TCP retransmits per second

10. top

The top command contains more statistics about indicators. It is equivalent to a comprehensive command.

$top top - 00:15:40 up 21:56, 1 user, load average: 31.09, 29.87, 29.92 Tasks: 871 total, 1 running, 868 sleeping, 0 stopped, 2 zombie %Cpu(s): 96.8us, 0.sy, 0.0Ni, 2.7ID, 0.1wa, 0.0Hi, 0.0si, 0.0st KiB Mem: 25190241+total, 24921688 used, 22698073+free, 60448 buffers KiB Swap: 0 total, 0 used, 0 free. 554208 cached Mem PID USER PR NI VIRT RES SHR S %CPU % Mem TIME+ COMMAND 20248 root 20 0 0.227t 0.012t 18748 S 3090 5.2 29812:58 Java 4213 root 20 0 2722544 64640 44232 S 23.5 0.0 233:35.37 mesos-slave 66128 titancl+ 20 0 24344 2332 1172 R 1.0 0.0 0:00.07 Top 5235 root 20 0 38.227g 547004 49996 S 0.7 0.2 2:02.74 Java 4299 root 20 0 20.015g 2.682g 16836 S 0.3 1.1 33:14.42 Java 1 root 20 0 33620 2920 1496 S 0.0 0.0 0:03.82 init 2 root 20 00 00 S 0.0 0.0 0:00.02 Kthreadd 3 root 20 00 00 S 0.0 0.0 0:05.35 ksoftirqd/0 5 root 0-20 00 0 S 0.0 0.0 0:00.00 kworker/0 0H 6 root 20 00 0 0 0 S 0.0 0.0 0:06. 94 kworker/u256:8 root 20 0 0 0 0 0 S 0.0 0.0 2:38. 05 rcu_sched12345678910111213141516171819Copy the code

conclusion

I sort out a: Linux related information, Java systematic information: (including Java core knowledge points, interview topics and 20 years of the latest Internet real questions, e-books, etc.) friends in need can follow the public number [program Yuanxiaowan] can get.