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 training-Optimization

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

one。 Hardware optimization

The speed of the system is determined by the slowest device in the system.

Select a solid state disk:

TLC SLC (preferably) MLC

When optimizing, optimize the device closest to the cpu

CPU-- > CACHE

Main frequency: frequency doubling * FSB

CACHE: cache buffer to improve the hit rate of applications. L1 (data area, instruction area) independent-> L2 independent-> L3 sharing

Optimization idea: find ways to keep the application data in cache for a longer time.

Application running process:

DISK-- > MEM-- > cache-- > CPU

DISK: optimizing IO algorithm

SSD: SATA3-- > PCIe-- > NVMe

two。 System level

1. Common command

(1) ps

Custom display process column

# ps axo pid,comm,pcpu

(2) vmstat

# vmstat 1 2procs-memory- swap---io-----system---cpu- r b swpd free buff cache si so bi bo in cs us sy id wa st 3 0148 284184 12 663928 0 12 5 81 121 0 0 99 0 0 0 284060 212 663928 00 00 96 126 00 100 00 r indicates the run queue (that is, how many processes are actually assigned to CPU) The CPU of the server I tested is currently idle, and there are no programs running. When this value exceeds the number of CPU, there will be a CPU bottleneck. This also has something to do with the load of top. Generally, if the load exceeds 3, it is high, if it exceeds 5, it is high, and if it exceeds 10, it is abnormal. The state of the server is very dangerous. The load of top is similar to the run queue per second. If the running queue is too large, it means that your CPU is very busy, which generally results in high CPU utilization. B means blocked process, not to mention, process blocking, we all know. The size of swpd virtual memory that has been used, if it is greater than 0, indicates that your machine is out of physical memory. If it is not the cause of the program memory leak, then you should upgrade the memory or migrate memory-consuming tasks to other machines. The size of free's free physical memory, my machine has a total of 8g of memory, leaving 3415m. The buff Linux/Unix system is used to store the cache of what contents and permissions are in the directory. My machine takes up more than 300m Mcache cache to directly remember the files we open and buffer the files. My computer takes up more than 300m (here is the wisdom of Linux/Unix. I use part of the free physical memory to cache files and directories in order to improve the performance of program execution. When the program uses memory, it is used to cache files and directories. Buffer/cached will be used quickly.) Si reads the amount of virtual memory from disk per second. If this value is greater than 0, it means that the physical memory is insufficient or there is a memory leak. Find the memory-consuming process to solve it. My machine has plenty of memory and everything is fine. So the amount of virtual memory written to disk per second. If this value is greater than 0, it is the same as above. The number of blocks received by bi block devices per second. The block devices here refer to all disks and other block devices on the system. The default block size is 1024byte. There is no IO operation on my computer, so it has always been 0, but I have seen that it can reach 140000amp s on a machine that processes copying large amounts of data (2-3T), and the disk write speed is about 140m per second. For example, the number of blocks sent by bo block devices per second, for example, we read files. Bo should be greater than 0. Bi and bo are generally close to 0, or IO is too frequent and needs to be adjusted. The number of interrupts per second of CPU in in, including the number of context switches per second when time interrupts cs. For example, when we call system functions, we need to switch context, thread switching, and process context switching. This value should be as small as possible, too large. Consider reducing the number of threads or processes, for example, in web servers such as apache and nginx. We usually carry out thousands or even tens of thousands of concurrent tests when we do performance tests. The process of choosing a web server can be downgraded from the peak of the process or thread to a relatively small value, and the number of processes and threads is a more appropriate value. The same is true of system calls. Every time a system function is called, our code will enter the kernel space, resulting in context switching, which is very resource-consuming, and we should try our best to avoid frequent calls to system functions. Too many context switching times means that most of your CPU is wasted on context switching, resulting in less time for CPU to do serious things, and CPU is not fully utilized, which is not advisable. Us user CPU time, I used to do encryption and decryption very frequently on a server, I can see that the us is close to 100 and the running queue reaches 80 (the machine is doing stress testing and the performance is not good). If the CPU time of the sy system is too high, it means that the system calls take a long time, for example, frequent IO operations. Id idle CPU time, generally speaking, id + us + sy = 100. generally speaking, I think id is idle CPU utilization, us is user CPU utilization, and sy is system CPU utilization. Wt wait time for IO CPU.

(3) iostat

# iostatLinux 3.10.0-693.el7.x86_64 (rh2) 08 CPU 2018 _ x86 Universe 641 avg-cpu:% user% nice% system% iowait% steal% idle 0.20 0.01 0.32 0.01 0.00 99.46Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtnsda 0.87 12.23 5.24 898971 385228scd0 0.00 0.01 0.00 1054 0dm-0 0.86 11.76 5.21 864302 383008dm-1 0.00 0.03 0.00 2228 152

Avg-cpu:

Option describes the percentage of time that% userCPU executes the process in user mode. % niceCPU in user mode, for nice operations,% percentage of total CPU time spent%% time spent executing processes in kernel mode% iowaitCPU spent waiting for CPU total time%% steal hypervisor (hypervisor) to service another virtual process% idleCPU idle time%% of virtual CPU while waiting for another virtual process.

Device:

The option describes the number of times the Device device name tps requests data from the disk device per second, including read and write requests, which is the sum of rtps and wtps. For the sake of efficiency, instead of processing requests immediately after each IO is issued, requests are merge, where tps refers to the number of requests merged. Blk_read/sIndicate the amount of data read from the device expressed in a number of blocks per second. Blocks are equivalent to sectors with kernels 2.4 and later and therefore have a size of 512 bytes. Total number of read sectors in With older kernels, a block is of indeterminate size.Blk_wrtn/sIndicate the amount of data written to the device expressed ina number of blocks per second.Blk_read sampling interval Blk_wrtn total number of write sectors in sampling interval

# iostat-xLinux 3.10.0-693.el7.x86_64 (rh2) 08 CPU 02Universe 2018 _ x86 Universe 641 avg-cpu:% user% nice% system% iowait% steal% idle 0.20 0.01 0.32 0.01 0.00 99.46Device: rrqm/s wrqm/s Randall s WJet s rkB/s wkB / s avgrq-sz avgqu-sz await r_await w_await svctm% utilsda 0.00 0.02 0.24 0.63 12.23 5.24 40.10 0.00 0.88 1.18 0.77 0.31 0.03scd0 0.00 0.00 0.00 0.01 0.00 68.00 0 . 00 0.35 0.35 0.00 0.35 0.00dm-0 0.00 0.00 0.21 0.64 11.75 5.21 39.57 0.00 0.94 1.33 0.80 0.31 0.03dm-1 0.00 0.00 0.00 0.03 0.00 36 . 06 0.00 7.01 0.05 24.21 1.21 0.00

Option indicates the number of times rrqm/s 's read requests to the device are merged per second The file system merges requests to read the same block (block) wrqm/s write requests to the device per second are merged, read requests to the device are merged, reads completed per second, rkB/s reads per second (in kB) wkB/s writes per second (in kB) avgrq-sz average amount of data per IO operation (in sectors) avgqu-sz average waiting place Average IO request queue length await average waiting time per IO request (including waiting time and processing time (in milliseconds) average processing time of each IO request by svctm (in milliseconds)% util uses the ratio of time spent on IO operations in the cycle, that is, the rate of time that the IO queue is not empty

(4) mpstat

Looking at the multicore cpu, you can show the operation of each core cpu. Vmstat can only display the overall cpu

# mpstat-P ALLLinux 3.10.0-693.el7.x86_64 (rh2) 08 take 02 CPU 10:13:33 PM CPU% usr% nice% iowait% irq% steal% guest% gnice% idle10:13:33 PM all 0.20 0.01 0.32 0.01 0.00 0.01 0.00 . 00 0.00 99.4610:13:33 PM 0 0.20 0.01 0.32 0.01 0.00 0.01 0.00 0.00 0.00 99.46

(5)。

# time ls

Real 0m0.006s

User 0m0.000s

Sys 0m0.005s

* 0.001s is the waiting time

(6). Sar

Sar log storage directory

Cd / var/log/sa

# sar-f sa31 # default cpu# sar-f sa31-b # View disk # sar-Q-f sa31 # View queue # sar-Q-f sa31 | awk'{print $3}'| sort-unr # process number of the largest queue # sar-d-p-f sa31 | awk'{print $2 $4}'| grep ^ sd | sort-unr # which device has the highest read rate # sar-n DEV # View network throughput # sar-r 1 1 # memory and swap usage

(7). Dmidecode

View detailed hardware information

(8) .lspci, lscpu,lsusb,lsscsi,lsblk

View various hardware information commands

(9). Dmesg

-record the hardware-related information when the system is started, and the log file will not be updated after startup

/ var/log/dmesg

-to view the hardware information loaded after the system starts, you need to check the dmesg.

2.sysctl

(1) .sysctl-a # shows all the currently adjustable parameters

(2)。 Modify configuration files and adjust parameters

Older versions of vim / etc/sysctl.conf

New version of vim / etc/sysctl.d/10-sysctl.conf

(3). Sysctl-p / etc/sysctl.d/10-sysctl.conf

Make the parameter permanent

3.swap

Swap can be a file or a disk partition, with a maximum of 32 files and a maximum of 64G each

Performance considerations:

Avoid swap files

Separate swap from fast media

Multiple small swap effects are better than a large swap effect to set the swap priority

4. Kernel IO Scheduler

-NooP Scheduler

Suitable for random access devices, such as flash drive FIFO, basic merge and sorting for embedded operating systems

-Anticipatory I Dot O Scheduler

Kernel default scheduler

Not suitable for database systems with large data throughput

-DeadLine Io scheduler

Improve IO performance while avoiding IO wait

Guarantee the minimum delay time for a given IO request

-CFQ I Dot O Schedulere

RHEL's default scheduler, IO, requests polling, which allocates bandwidth equally to applications and provides an equal working environment.

(1)。 Temporary modification

[root@rh2 ~] # cat / sys/block/sda/queue/scheduler

Noop [deadline] cfq

[root@rh2 ~] # echo cfq > / sys/block/sda/queue/scheduler

[root@rh2 ~] # cat / sys/block/sda/queue/scheduler

Noop deadline [cfq]

(2)。 Modify all configurations

Modify grub.conf # boot=/dev/hdadefault=0 timeout=5splashimage= (hd0,0) / grub/splash.xpm.gzhiddenmenutitle Red Hat Enterprise Linux Server (2.6.18-8.el5) root (hd0,0) kernel / vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet elevator=deadline initrd / initrd-2.6.18-8.el5.img

(3) tuned-adm

5. Memory optimization

Related parameters:

Vm.dirty_expire_centisecs = 0 # time for writing back old data. After 30 seconds, dirty pages are written back to disk vm.dirty_background_ratio = 10 # if the percentage of dirty pages in the whole system exceeds 3000, dirty pages are scrubbed vm.dirty_ratio = 30 # when the whole dirty pages reach 30% of memory Then scrubbing dirty pages vm.dirty_writeback_centisecs = 500 # interval between refreshing dirty data processes vm.swappiness=30 # using memory or swap preference

6. Network optimization

BDP bandwidth delay product

Calculation formula (bytes) = bandwidth (MB) x delay (s) x1024x1024/8

Related parameters:

Net.ipv4.tcp_mem = 194976 259968 389952net.ipv4.tcp_wmem = 4096 16384 4194304net.ipv4.tcp_rmem = 4096 87380 4194304net.ipv4.udp_mem = 194976 259968 389952net.core.wmem_max = 131071 net.core.rmem_max = 131071 net.core.wmem_default = 110592 net.core.rmem_default = 110592

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