Where can I start with Linux performance optimization?

Linux performance optimization has always been a common topic. I believe everyone has a certain understanding of optimization measures. But how to tune Linux performance, where to start, what is the underlying principle behind this, and why it is done this way, few people have made it clear. The following article analyzes the three major factors that affect Linux performance in detail. System hardware, operating system and operating system, you can get optimized specific solutions from these ideas.

1. System hardware

1、CPU

As we all know, the operating system is basically a stable CPU, and its performance fundamentally determines the overall performance of the system, so Linux performance optimization can start with the CPU. Generally speaking, the more CPUs and the higher the clock speed, the better the server performance. However, there are exceptions. Hyper-threaded processors can run multiple threads at the same time. Under Linux systems, only SMP kernels can support hyper-threading. However, the more CPUs installed, the higher the performance from hyper-threading. The less the improvement. Applications that may have a CPU bottleneck include db servers, dynamic web servers, etc. For such applications, CPU configuration and performance should be put in the main position.

2. Memory

In addition to the CPU, the size of the memory is also an important aspect that affects the performance of Linux. If the memory is too small, the system process will be blocked, the application will become slow, or even lose response; the memory is too large, resulting in waste of resources. Therefore, to use more memory, it is recommended to install a 64-bit operating system and enable Linux's large memory kernel support. Due to the limitation of the addressing range of the processor, on the 32-bit Linux operating system, a single application process can only use a maximum of 4GB of memory. In this way, even if the system has a larger memory, the application cannot "share" it. The solution is to use a 64-bit processor and install a 64-bit operating system. Under the 64-bit operating system, it can meet the memory usage requirements of all applications with almost no restrictions. The Linux system uses both physical memory and virtual memory. Although virtual memory can alleviate the shortage of physical memory, it occupies too much virtual memory, and the performance of the application will be significantly reduced. It is necessary to ensure the high-performance operation of the application. It must be large enough; but too large physical memory will cause a waste of memory resources.

3. Disk I/O performance

The I/O performance of the disk directly affects the performance of the application. In an application with frequent reads and writes, if the disk I/O performance is not satisfied, the application will stagnate. Fortunately, today's disks have adopted many methods to improve I/O performance, such as common disk RAID technology. A disk group composed of RAID technology is equivalent to a large hard disk. Users can partition and format it, create file systems and other operations. It is exactly the same as a single physical hard disk. The only difference is the I/O performance ratio of the RAID disk group. A single hard disk is much higher, and the data security is also greatly improved.

4. Internet broadband

Various applications under Linux are generally network-based, so network bandwidth is also an important aspect that affects performance. A low-speed and unstable network will cause access to network applications to block, while stable and high-speed network bandwidth can Ensure that applications run smoothly on the network. Fortunately, current networks are generally gigabit bandwidth or optical fiber networks, and the impact of bandwidth issues on application performance is gradually decreasing.

Two, operating system

1. Install the system

System optimization can start from the installation of the operating system. When installing the Linux system, the partition of the disk and the allocation of SWAP memory will directly affect the performance of the future system. For example, disk allocation can follow application requirements. With the decrease of memory price and the increasing of memory capacity, there is no requirement for virtual memory SWAP to be twice the physical memory. However, the SWAP setting cannot be ignored. According to experience, if The memory is small, generally set the SWAP swap partition size to twice the memory; if the physical memory is greater than 8GB and less than 16GB, you can set the SWAP size to be equal to or slightly smaller than the physical memory; if the memory size is more than 16GB, in principle, you can set SWAP to 0, but this is not recommended, because setting a certain size of SWAP still has a certain effect.

2. Kernel parameters

After the system is installed, the optimization work is not over. Next, the system kernel parameters can be optimized, but the optimization of the kernel parameters should be considered as a whole with the applications deployed in the system. For example, if the system deploys an Oracle database application, then you need to optimize the settings of the system shared memory segment, system semaphore, file handle and other parameters; if you deploy a web application, then you need to set the network parameters according to the characteristics of the web application Optimization, such as modifying network kernel parameters such as net.ipv4.ip_local_port_range, net.ipv4.tcp_tw_reuse, net.core.somaxconn, etc.

3. File system

File system optimization is also a focus of system resource optimization. File systems available under Linux include ext2, ext3, ReiserFS, ext4, and xfs. According to different applications, choose different file systems. The Linux standard file system starts with VFS, then ext, and then ext2. It should be said that ext2 is the standard file system on Linux, and ext3 is formed by adding logs on the basis of ext2. From VFS to ext4, the design idea is not The big changes are the design concepts of the early UNIX family based on superblocks and inodes. XFS file system is an advanced log file system. XFS provides low-latency and high-bandwidth access to file system data by distributed processing disk requests, locating data, and maintaining Cache consistency. Therefore, XFS is extremely scalable and robust. , It has the advantages of excellent log recording function, strong scalability, and fast writing performance. At present, server-side ext4 and xfs are the mainstream file systems. How to choose a suitable file system needs to be determined based on the characteristics of the file system and the needs of the business.

Three, application software

1. Operation and maintenance

In the process of thinking about Linux performance optimization, Linux operation and maintenance is taking on very important tasks. First of all, Linux operation and maintenance personnel must understand and master the current operating status of the operating system. This information is the basis and basis for detecting and judging system performance; secondly, Linux operation and maintenance personnel must also grasp the hardware information of the system, and then comprehensively evaluate it based on this information The usage of system resources. As a Linux operation and maintenance personnel, you must also grasp the usage of system resources by the application. A more in-depth point is to understand the operating efficiency of the application. By monitoring the system resources, you can find out whether the application is abnormal. There is indeed a problem with the application, and the problem needs to be reported to the program developer immediately to improve or upgrade the program. Performance optimization itself is a complex and tedious process. Only when Linux operation and maintenance personnel understand system hardware information, network information, operating system configuration information, and application program information, can they perform targeted optimization of server performance. This requires Linux operation Maintenance personnel have sufficient theoretical knowledge, rich practical experience and a mind to analyze problems carefully.

2. System architecture design

The second type of personnel involved in system performance optimization is application architecture designers. If after a comprehensive judgment in the Linux operation and maintenance link, it is found that the performance is affected by the execution efficiency of the application, then the program architecture designer must intervene in time to understand the program's running status. First of all, the system architecture designer must track the execution efficiency of the program. If there is a problem with the execution efficiency, find out where the problem occurred; second, if there is a problem with the architecture design, then immediately optimize or improve the system architecture. Design better application system architecture.

3. Software development

The last link of system performance optimization involves program developers. After Linux operation and maintenance personnel or architecture designers find a program or structural bottleneck, program developers should immediately intervene to make corresponding program modifications. Modify the program based on the execution efficiency of the program, improve the logic of the program, and optimize the code in a targeted manner. System performance optimization generally follows the process: First, Linux operation and maintenance personnel check the overall status of the system. If it is found that the system hardware, network equipment or operating system configuration problem, Linux operation and maintenance personnel can solve it independently according to the situation; if it is found to be a program structure problem , It needs to be submitted to the program architecture designer; if the program code execution problem is found, it is handed over to the developer for code optimization. This completes a process of system performance optimization.

In summary, Linux performance optimization can mainly start from the system hardware, operating system, and application software. Generally speaking, it is only a logical process to find out where Linux performance needs to be optimized through such a step-by-step careful inspection and investigation and solve the problem immediately. Friends who are still worried about Linux performance optimization, might as well give it a try right away.

Guess you like

Origin blog.csdn.net/JACK_SUJAVA/article/details/109185655