In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The knowledge points of this article include: the factors that affect the performance of Linux, the methods of Linux system performance optimization, reading the complete article, I believe you have a certain understanding of Linux system performance optimization.
I. Overview of performance problems
System performance refers to the effectiveness, stability and response speed of the operating system to complete the task. Linux system managers often encounter problems such as system instability and slow response. For example, when a web service is built on Linux, there are often phenomena such as web pages can not be opened and slow opening speed, while when they encounter these problems, some people complain that the Linux system is not good. In fact, these are all superficial phenomena. When the operating system completes a task, it is closely related to the system settings, network topology, routing devices, routing strategies, access devices, physical lines and other aspects. Any link that has problems will affect the performance of the entire system. Therefore, when there is a problem in Linux application, it should be comprehensively investigated from the aspects of application, operating system, server hardware, network environment, etc., locate the problem in that part, and then focus on solving it.
In the aspects of application, operating system, server hardware, network environment and so on. The biggest impact on performance is the two aspects of the application and the operating system, because the problems in these two aspects are not easy to detect and are highly hidden. As long as there are problems in hardware and network, they can generally be located immediately. This blog mainly introduces the performance tuning ideas of the operating system, and the specific problems need to be dealt with in the application.
The following introduces the general ideas and methods of optimizing Linux from four aspects: factors that affect Linux performance, personnel who analyze performance design, system performance optimization tools, and system performance evaluation criteria.
2. Factors affecting Linux performance 1) system hardware resources 1) CPU
CPU is the foundation of the stable operation of the operating system, and the speed and performance of CPU determine the overall performance of the system to a great extent. Therefore, the more the number of CPU and the higher the main frequency, the better the performance of the server. But trying is not entirely the case.
Currently, most CPU can only run one thread at a time, and hyperthreaded processors can run multiple threads at the same time. Therefore, the hyper-threading feature of the processor can be used to improve system performance. On Linux systems, hyper-threading can only be supported by running the SMP kernel, but the more CPU installed, the less performance improvement you will get from hyper-threading. In addition, the Linux kernel will identify multi-core processors as multiple separate CPU. For example, two 4-core CPU will be treated as 8 single-core CPU under Linux system. However, from a performance point of view, two 4-core CPU and 8 single-core CPU are not completely equivalent. According to the test conclusion drawn by the authoritative department, the overall performance of the former is 25% and 30% lower than that of the latter.
The applications that may have CPU bottlenecks are db server, dynamic Web server and so on. For such applications, the configuration and performance of CPU should be put in the main position.
2) memory
The size of memory is also an important factor affecting the performance of Linux, memory is too small, the system process will be blocked, the application will become slow, or even lose response; too much memory, resulting in a waste of resources. Linux system adopts both physical memory and virtual memory. Although virtual memory can alleviate the shortage of physical memory, it takes up too much virtual memory, and the performance of the application will be significantly degraded. In order to ensure the high performance of the application, the physical memory must be large enough. However, too much physical memory will result in a waste of memory resources. for example, on a 32-bit processor Linux operating system, physical memory exceeding 8GB will be wasted. Therefore, to use more memory, it is recommended to install a 64-bit operating system and turn on Linux's large memory kernel support.
Due to the limitation of the addressing range of the processor, on the 32-bit Linux operating system, an application can only use 4GB memory for a single process, so that even if the system has more memory, the application can not "enjoy" 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 requirements of all applications, with almost no restrictions.
Applications that may have memory performance bottlenecks include NOSQL servers, database servers, cache servers and so on. For such applications, memory size should be put in the main position.
3) disk Icano performance
The performance of disk Icano directly affects the performance of the application. In an application with frequent reads and writes, if the performance of disk Icando is not satisfied, it will lead to application stagnation. Fortunately, today's disks use a number of methods to improve the performance of Imax O, such as the common disk RAID technology.
The disk group composed of RAID technology is equivalent to a large hard disk, and users can format partitions, establish file systems and other operations on it, just like a single physical hard disk, except that the performance of RAID disk group is much higher than that of a single hard disk. At the same time, the security of the data is also greatly improved.
According to the different disk combinations, RAID can be divided into RAID0,RAID1, RAID2, RAID3, RAID4, RAID5, RAID6, RAID7, RAID0+1, RAID10 and other levels. The commonly used RAID levels are RAID0, RAID1, RAID5, RAID0+1, which are briefly introduced here.
RAID 0: striped volumes, which improve disk performance and throughput by gluing multiple hard drives into a larger hard disk group. This method is low-cost and requires at least two disks, but there is no fault tolerance and data repair, so it can only be used in environments that do not require high data security.
RAID 1: mirror volume, which maximizes the reliability and repairability of disk data by mirroring the data from one disk to another, and has high data redundancy, but the disk utilization rate is only 50%. Therefore, the cost is the highest, and it is often used to save important data.
RAID5: disk segmentation plus parity technology is adopted to improve the reliability of the system. RAID5 read efficiency is very high, write efficiency is general, at least 3 disks are needed. Allow a disk failure without affecting the availability of the data.
RAID0+1: combine RAID0 and RAID1 technology to form RAID0+1, which requires at least four hard drives. In addition to distributing data on multiple disks, each disk has its own mirror disk, which provides full redundancy, while allowing a disk failure without affecting data availability, and has fast read / write capabilities.
By understanding the performance of each RAID level, you can choose the appropriate RAID level according to the different characteristics of the application, so as to ensure that the application achieves the best performance on disk.
4) Network bandwidth
All kinds of applications under Linux are generally based on network, so network bandwidth is also an important factor affecting performance. Low-speed and unstable network will lead to access blocking of network applications, while stable and high-speed network bandwidth can ensure that applications can run smoothly on the network. Fortunately, today's networks are generally gigabit bandwidth or optical fiber networks, and the impact of bandwidth problems on application performance is gradually decreasing.
2) operating system related resources
The performance optimization based on the operating system is also multifaceted, which can be measured from several aspects, such as system installation, system kernel parameters, network parameters, file system and so on.
1) Optimization of system installation
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 system in the future.
For example, disk allocation can follow the requirements of the application:
1) for applications with frequent write operations and low data security requirements, the disk can be made into RAID 0.
2) for applications with high data security and no special requirements for reading and writing, the disk can be made into RAID 1.
3) for applications with high requirements for read operations, but no special requirements for write operations, and to ensure data security, you can choose RAID 5.
4) for applications with high reading and writing requirements and high data security requirements, you can choose RAID10/01
In this way, different RAID levels are set according to different application requirements, and the system is optimized at the bottom of the disk.
With the decrease of memory price and the increase of memory capacity, the setting of virtual memory SWAP no longer requires that virtual memory is twice as much as physical memory, but the setting of SWAP can not be ignored. According to experience:
1) if the memory is small (physical memory is less than 4GB), the SWAP swap partition size is generally set to 2 times the memory size.
2) if the physical memory is greater than 8GB and less than 16GB, you can set the SWAP size to be equal to or slightly less than physical memory.
3) 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) Kernel parameter optimization
After the installation of the system, the optimization work is not finished, and then the kernel parameters can be optimized, but the optimization of kernel parameters should be considered with the applications deployed in the system as a whole.
For example, if the system deploys Oracle database applications, you need to optimize the parameters such as system shared memory segments (kernel.shmmax, kernel.shmmni, kernel.shmall), system semaphores (kernel.sem), file handles (fs.file-max), and so on. If the Web application is deployed, the network parameters need to be optimized according to the characteristics of the Web application, such as modifying the network kernel parameters such as net.ipv4.ip_local_port_range, net.ipv4.tcp_tw_reuse, net.core.somaxconn and so on.
3) File system optimization
The optimization of file system is also a focus of system resource optimization. The optional file systems under Linux are ext2, ext3, ReiserFS, ext4 and xfs. According to different applications, choose different file systems.
Linux standard file system starts from VFS, then ext, then ext2. It should be said that ext2 is a standard file system on Linux, and ext3 is formed by adding logs on the basis of ext2. From VFS to ext4, its design idea has not changed much. It is the design concept of the early UNIX family based on super block and inode.
XFS file system is an advanced journal file system. XFS provides low-latency and high-bandwidth access to file system data through distributed processing of disk requests, positioning data, and maintaining the consistency of Cache. Therefore, XFS is very scalable and robust, with excellent logging functions, strong scalability, fast write performance and other advantages.
At present, server-side ext4 and xfs are the mainstream file systems. How to choose an appropriate file system needs to be determined according to the characteristics of the file system and the needs of the business.
3) Application software resources
In fact, application optimization is the core of the whole optimization project. If an application has BUG, even if all other aspects reach the optimal state, the performance of the whole application system is still low. Therefore, application optimization is the top priority of the performance optimization process, which puts forward higher requirements for program architecture designers and program developers.
3. Analysis of system performance design personnel 1) Linux operation and maintenance personnel
In the process of performance optimization, Linux operation and maintenance personnel undertake very important tasks:
1) first of all, Linux operators should understand and master the current running state of the operating system, such as system load, memory status, process status, CPU load and so on, which are the basis and basis for detecting and judging system performance.
2) secondly, the Linux operation and maintenance staff also master the hardware information of the system, such as disk ID O, CPU model, memory size, network card bandwidth and other parameter information, and then comprehensively evaluate the use of system resources based on these information.
3) as a Linux operation and maintenance staff, it is also necessary to master the application's use of system resources, and a deeper point is to understand the running efficiency of the application, such as whether there are problems such as program BUG, memory overflow and so on. Through the monitoring of system resources, we can find out whether there is an exception in the application. If there is a problem in the application, we need to immediately reflect the problem to the program developer. And then improve or upgrade the program.
Performance optimization itself is a complex and tedious process, Linux operation and maintenance personnel can only understand the system hardware information, network information, operating system configuration information and application information to optimize the server performance, which requires Linux operators to have sufficient theoretical knowledge, rich practical experience and the mind of careful analysis of problems.
2) system architecture designer
The second category of people involved in system performance optimization are the application architects. If the Linux operation and maintenance staff after a comprehensive judgment, found that the impact on the performance is the execution efficiency of the application, then the program architecture designer should intervene in time to deeply understand the running state of the program.
1) first of all, the system architecture designer should track and understand the execution efficiency of the program, and if there is a problem with the execution efficiency, find out what went wrong.
2) secondly, if there is really something wrong with the architecture design, it is necessary to optimize or improve the system architecture and design a better application system architecture.
3) Software developers
The last link of system performance optimization involves program developers. After Linux operation and maintenance personnel or architecture designers find the program or structural bottleneck, program developers should immediately intervene to modify the corresponding program. The modification of the program should be based on the execution efficiency of the program, improve the logic of the program, and optimize the code pertinently. For example, Linux operators find a SQL statement in the system that consumes a lot of system resources, grab the executed SQL statement, and find that the execution efficiency of the SQL statement is too poor, which is caused by the low execution efficiency of the code written by the developer, which needs to feed back this information to the developer. After receiving this problem, the developer can optimize the SQL targeted to achieve the optimization of the program code.
As can be seen from the above process, the general process of system performance optimization is as follows:
1) first of all, the Linux operation and maintenance personnel check the overall status of the system, and make a comprehensive judgment mainly from five aspects: system hardware, network equipment, operating system configuration, application architecture and program code. If it is found that it is a system hardware, network equipment or operating system configuration problem, the Linux operation and maintenance personnel can solve it independently according to the situation.
2) if it is found that it is a program structure problem, it needs to be submitted to the program architecture designer
3) if it is found that there is a problem with the execution of the program code, give it to the developer for code optimization
4) in this way, a process of system performance optimization is completed!
IV. Summary of tuning
System performance optimization is a wide-ranging, tedious and long-term work, to find the root cause of the performance problem is often the most difficult part, once the cause of the problem is found, the performance problem will be easily solved. Therefore, the way to solve the problem becomes very important.
For example, in a website system under the linux system, users report that the access speed of the website is very slow and sometimes inaccessible.
The solution to this problem is:
1) to detect the network, you can use the ping command to check whether the domain name resolution of the website is normal, and at the same time, whether the delay of the ping server address is too large, etc., in this way, you can first rule out the problems that may occur in the network; if there is no problem with the network
2) check the memory usage of the linux system, because the response speed of the website is slow and generally has a large correlation with memory. Use free, vmstat and other commands to determine whether the memory resources are scarce, if there is no problem with the memory resources.
3) check the load status of the system CPU, and you can comprehensively judge whether the CPU is overloaded by the output of sar, vmstat, top and other commands, if there is no problem with the CPU.
4) check whether there is a bottleneck in the disk IAccord O of the system. You can use iostat, vmstat and other commands to check the read and write performance of the disk. If there is no problem with reading and writing the disk, the performance problem of the linux system itself is basically eliminated. The last thing to do is to check whether there is a problem with the program itself. Through this way of thinking, testing layer by layer and troubleshooting step by step, the performance problem "has no place to hide", and it becomes very simple to find the link where the performance problem occurs.
After reading this article, have you learned the method of Linux system performance optimization? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.