Contents
Linux operating system is an open source product, and is also an open source software practice and application platform.
There are countless open source software support under this platform. Our common apache
, tomcat
, mysql
, php
, etc., the biggest idea of ​​open source software is freedom, Open, then Linux as an open source platform, the ultimate realization is through the support of these open source software, to achieve the best performance at the lowest cost. Therefore, when it comes to performance issues, the main implementation is the best combination of Linux operating system and application.
1. A summary of performance issues
The performance of the system refers to the effectiveness, stability, and responsiveness of the operating system to complete the task. Linux system administrators may often encounter problems such as unstable system and slow response. For example, a web service is built on linux. It often happens that web pages cannot be opened and opened slowly. When encountering these problems, some people will Complaining that the Linux system is not good, in fact, these are superficial phenomena. When the operating system completes a task, it is closely related to the system’s own settings, network topology, routing devices, routing policies, access devices, and physical lines. Any problem in one link will affect the performance of the entire system. Therefore, when there is a problem with the linux application, it should be comprehensively checked from the application, operating system, server hardware, network environment, etc., where the positioning problem occurs, and then centralized solution.
In terms of applications, operating systems, server hardware, network environment, etc., the most influential performance is the application and the operating system, because the problems in these two aspects are not easy to detect, and the concealment is very strong. As long as there are problems in the hardware and network, they can usually be located immediately. The following mainly explains the performance tuning ideas of the operating system, and the application needs specific issues to be treated.
The following describes the general ideas and methods for optimizing Linux from four aspects: factors affecting Linux performance, personnel involved in analyzing performance, system performance optimization tools, and system performance evaluation criteria.
2. Factors that affecting Linux performance
2.1 System hardware resources
1. CPU
The CPU is the fundamental operation of the operating system. The speed and performance of the CPU largely determine the overall performance of the system. Therefore, the more CPUs and the higher the frequency, the better the server performance. But the truth is not entirely true.
At present, most CPUs can only run one thread at a time. Hyper-threaded processors can run multiple threads at the same time. Therefore, the processor’s hyper-threading feature can be used to improve system performance. Under Linux, hyperthreading is only supported by running the SMP kernel, but the more CPUs are installed, the less performance improvements are obtained from hyperthreading. In addition, the Linux kernel will recognize multi-core processors as multiple CPUs, such as two 4-core CPUs, which will be treated as eight single-core CPUs under the Lnux system. However, from a performance point of view, the two 4-core CPUs and the eight single-core CPUs are not completely equivalent. According to the test conclusions drawn by the authoritative department, the overall performance of the former is 25% to 30% lower than the latter.
Applications that may have CPU bottlenecks include db servers, dynamic web servers, etc. For such applications, the configuration and performance of the CPU should be placed at the main location.
2. RAM
The size of memory is also an important factor affecting Linux performance. Memory is too small, system processes will be blocked, applications will become slow, and even lose response; memory is too large, resulting in wasted resources. Linux system uses physical memory and virtual memory. Although virtual memory can alleviate the shortage of physical memory, but the excessive virtual memory, the performance of the application will be significantly reduced, to ensure the high-performance operation of the application, physical memory It must be large enough; but too much physical memory will waste memory resources. For example, on a 32-bit processor Linux operating system, more than 8GB of physical memory will be wasted. Therefore, to use larger 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 processor’s addressing range, on a 32-bit Linux operating system, a single process can only use up to 4 GB of memory. This way, even if the system has more memory, the application cannot be “shared” and solved. 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, and there are almost no restrictions.
Applications that may experience memory performance bottlenecks include NOSQL servers, database servers, cache servers, etc. For such applications, the memory size is placed at the primary location.
3. Disk I/O performance
Disk I/O performance directly affects application performance. In an application with frequent reads and writes, if disk I/O performance is not met, the application will stall. Fortunately, today’s disks use a number of methods to improve I / O performance, such as the common disk RAID technology.
A disk group consisting of RAID technology is equivalent to a large hard disk. Users can format and format the file system, and create a file system. The only difference is the I/O performance ratio of the RAID disk group. A single hard drive is much higher, and the security of the data is greatly improved.
Depending on the combination of disks, RAID can be divided into RAID0, RAID1, RAID2, RAID3, RAID4, RAID5, RAID6, RAID7, RAID0+1, and RAID10. Common RAID levels are RAID0, RAID1, RAID5, and RAID0+1. Here is a brief introduction.
RAID 0: Improves disk performance and throughput by bonding multiple hard drives into a larger capacity disk group. This method is low in cost and requires at least two disks, but it has no fault tolerance and data repair functions, so it can only be used in an environment where data security is not demanding.
RAID 1: Disk mirroring, which maximizes the reliability and repairability of disk data by mirroring the data of one disk to another, has high data redundancy, but disk utilization is only 50%, therefore, the highest cost, used in the case of saving important data.
RAID5: Disk segmentation plus parity technology is adopted to improve system reliability. RAID5 has high readout efficiency and general write efficiency. It requires at least 3 disks. Allow a disk to fail without affecting the availability of data.
RAID0+1: Combining RAID0 and RAID1 technology becomes RAID0+1, requiring at least 4 hard disks. In addition to being distributed across multiple disks, each disk has its own mirrored disk, providing full redundancy while allowing one disk failure without compromising data availability and fast read/write capabilities.
By understanding the performance of each RAID level, you can choose the RAID level that suits you according to the different characteristics of the application, so as to ensure the optimal performance of the application in terms of disk.
4. Network broadband
Various applications under Linux are generally network-based, so network bandwidth is also an important factor affecting performance. Low-speed, unstable networks will cause network application access blocking, while stable, high-speed network bandwidth can Ensure that the application runs unimpeded on the network. Fortunately, today’s networks are typically gigabit bandwidth or fiber-optic networks, and the impact of bandwidth issues on application performance is steadily declining.
2.2 Operating System Related Resources
The performance optimization based on the operating system is also multi-faceted, which can be measured from several aspects such as system installation, system kernel parameters, network parameters, file system, etc.
2.2.1 System installation optimization
System optimization can start from the installation of the operating system. When installing a Linux system, the partitioning of disks and the allocation of SWAP memory directly affect the running performance of the system in the future. For example, disk allocation can follow the requirements of the application: for data write operations frequently For applications with low security requirements, the disk can be made into RAID 0. For applications with high data security and no special requirements for reading and writing, the disk can be made into RAID 1; For applications that do not require special write operations and to ensure data security, RAID 5 can be selected. For applications with high read and write requirements and high data security requirements, RAID 10/01 can be selected. In this way, different RAID levels are set through different application requirements, and the system is optimized at the bottom of the disk.
With the reduction of memory price and the increasing memory capacity, the setting of virtual memory SWAP has no requirement that virtual memory is twice the physical memory, but the setting of SWAP can not be ignored. According to experience, if The memory is small (physical memory is less than 4GB), generally the SWAP swap partition size is 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 above 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.2.2 Kernel parameter optimization
After the system is installed, the optimization work is not finished. Next, the system kernel parameters can be optimized. However, the optimization of the kernel parameters should be considered together with the applications deployed in the system. For example, if the system is deployed with an Oracle database application, then you need to share the memory segment (kernel.shmmax, kernel.shmmni, kernel.shmall), system semaphore (kernel.sem), file handle (fs.file-max). ) and other parameters to optimize settings; if you are deploying a web application, you need to optimize the network parameters according to the characteristics of the web application, such as modifying network kernel parameters such as net.ipv4.ip_local_port_range, net.ipv4.tcp_tw_reuse, net.core.somaxconn .
2.2.3 File system optimization
File system optimization is also a key point of system resource optimization. The optional file systems under Linux include ext2, ext3, ReiserFS, ext4, and xfs. Different file systems are selected according to different applications.
The Linux standard file system starts from VFS, then ext, and then ext2. It should be said that ext2 is the standard file system on Linux, and ext3 is added on the basis of ext2. From VFS to ext4, the design idea is not Too big changes are the design concepts of the early UNIX family based on superblocks and inodes.
The XFS file system is an advanced log file system. XFS provides low-latency, high-bandwidth access to file system data by distributing disk requests, locating data, and maintaining Cache consistency. Therefore, XFS is very scalable and very robust. , with excellent logging capabilities, scalability, fast write performance and so on.
At present, the server-side ext4 and xfs are the mainstream file systems. How to choose the appropriate file system needs to be determined according to the characteristics of the file system and the needs of the business.
2.3 Application software resources
Application optimization is actually the core of the entire optimization project. If an application has a bug, even if all other aspects are in an optimal state, the entire application system is still inferior. Therefore, the optimization of the application is the performance optimization process. The most important thing is that the requirements of program architecture designers and program developers are higher.
3. Analyze the personnel involved in system performance
3.1 Linux operation and maintenance personnel
In the process of performance optimization, Linux operation and maintenance personnel bear a very important task. First, Linux operation and maintenance personnel should understand and master the current operating state of the operating system, such as system load, memory status, process status, CPU load, etc. This information is the basis and basis for detecting and judging the performance of the system. Secondly, the Linux operation and maintenance personnel also have the hardware information of the system, such as disk I/O, CPU model, memory size, network card bandwidth and other parameter information, and then comprehensively based on this information. Evaluate the use of system resources; thirdly, as a Linux operation and maintenance personnel, you must also grasp the application’s use of system resources. A deeper point is to understand the application efficiency, such as whether there are program BUGs, memory. Overflow and other issues, through the monitoring of system resources, you can find out whether the application is abnormal. If there is a problem with the application, you need to immediately reflect the problem to the program developer, and then improve or upgrade the program.
Performance optimization itself is a complicated and cumbersome process. Linux operation and maintenance personnel can only understand the system hardware information, network information, operating system configuration information and application information in order to optimize the performance of the server. This requires Linux to be shipped. The U.S. personnel have sufficient theoretical knowledge, rich practical experience, and a mindful analysis of the problem.
3.2 System architecture designer
The second type of staff involved in system performance optimization is the application architect of the application. If the Linux operation and maintenance personnel find out that the performance impact is the execution efficiency of the application after comprehensive judgment, the program architecture designer must intervene in time to gain an in-depth understanding of the program running status. First, the system architecture designer should track the execution efficiency of the program. If there is a problem with the execution efficiency, find out where the problem occurs. Secondly, if there is a problem with the architecture design, then the system architecture should be optimized or improved immediately. Design a better application architecture.
3.3 Software developers
The last step of system performance optimization involves the program developer. After the Linux operation and maintenance personnel or architects find the program or structural bottleneck, the program developer should immediately intervene to modify the program. The modification program should improve the logic of the program based on the execution efficiency of the program, and optimize the code in a targeted manner. For example, Linux operation and maintenance personnel found a SQL statement in the system that consumes a lot of system resources, grabs this executed SQL statement, and finds that the execution efficiency of this SQL statement is too poor, which is caused by the low efficiency of code written by the developer. This requires feedback to the developer. After receiving the problem, the developer can perform SQL optimization in a targeted manner to optimize the program code.
From the above process, it can be seen that the system performance optimization generally follows the following steps: First, the Linux operation and maintenance personnel view the overall status of the system, mainly from five aspects: system hardware, network equipment, operating system configuration, application architecture, and program code. Comprehensive judgment, if it is found that the system hardware, network equipment or operating system configuration problems, Linux operation and maintenance personnel can solve the problem 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 it is found that the program code execution problem Then give the developer code optimization. This completes a process of system performance optimization.
4. Tuning summary
System performance optimization is a wide-ranging, cumbersome, long-term work. Finding the root cause of performance problems is often the hardest part. Once the cause of the problem is found, the performance problem will be solved. Therefore, the solution to the problem has become very important.
For example, a website system under the Linux system, users report that the website access speed is very slow and sometimes inaccessible.
To solve this problem, the first step is to detect the network. You can use the ping command to check whether the domain name resolution of the website is normal. At the same time, the delay of the ping server address is too large. In this way, the network may be excluded first. If there is no problem with the network, then go to the second step, check the memory usage of the Linux system, because the website response speed is slow, generally associated with the memory, through free, vmstat and other commands to determine whether the memory resources are scarce, if There is no problem with the memory resources. Go to the third step and check the load status of the system CPU. You can use the output of sar, vmstat, top and other commands to comprehensively determine whether the CPU has an overload problem. If the CPU has no problem, continue to the fourth step and check the system. Whether there is a bottleneck in the disk I / O, you can check the read and write performance of the disk through iostat, vmstat and other commands, if the disk read and write is no problem, the performance problems of the Linux system itself are basically excluded, the last thing to do is to check whether the program itself exists. problem. Through this kind of thinking, layer detection, step by step, performance problems are “nowhere to hide”, it is very simple to find the link that has performance problems.
Discussion about this post