The method of performance tuning for Linux operating system 2013-03-18 15:35 Honestqiao Chinaunixfont Size:T | T
Linux is a free-to-use and free-to-propagate Unix-like operating system, with different Linux distributions and different kernels making changes to the parameters and settings, allowing the system to achieve better performance. This article shares several techniques for optimizing the performance of Linux operating systems.
AD:2014WOT Global Software Technology Summit Beijing Station course video release
Traditionally, different Linux distributions and different kernels have changed the parameters and settings, allowing the system to achieve better performance. Below is a four-part introduction to the performance optimizations under Red Hat Enterprise Linux as and SUSE Linux Enterprise Server systems using the following techniques:
QUOTE:
1, disabling daemons (Close daemons)
2. Shutting down the GUI (turn off GUI)
3, changing kernel parameters (change kernel parameters)
4, Kernel parameters (kernel parameter)
5. Tuning the processor subsystem (processor subsystem tuning)
6. Tuning the memory subsystem (in-system tuning)
7. Tuning the file System (FileSystem subsystem tuning)
8. Tuning the network subsystem (subsystem tuning)
1 Close Daemons
Some daemons (background services) that run on the server are not completely necessary. Turning off these daemons frees up more memory, reduces startup time, and reduces the number of processes processed by the CPU. Reducing the number of daemons also enhances the security of the server. By default, a few daemons can be safely stopped by most servers.
Table 10-1 lists the adjustable processes under red Hat Enterprise Linux as.
Table 10-2 lists the adjustable processes under SuSE LINUX Enterprise server.
Note: Turning off XFS daemon will cause X to not start, so you can close XFS daemon only if you do not need to start GUI graphics. Before using the StartX command, turn on XFS daemon and resume normal boot X.
You can stop a process as needed, such as to stop the sendmail process and enter the following command:
Red Hat:/sbin/service sendmail stopsuse LINUX:/etc/init.d/sendmail stop
You can also configure whether a process is not started automatically at the next boot, or sendmail:
Red Hat:/sbin/chkconfig sendmail offsuse LINUX:/sbin/chkconfig-s sendmail off
In addition, Linux provides process management capabilities in a graphical manner. For Red Hat, start the GUI and use the following command:/usr/bin/redhat-config-services or mouse click Main Menu, System Settings
Server Settings Services.
Tip: Not all daemons will be displayed in this configuration interface, if you want to see all the daemons, use the following command:
/sbin/chkconfig–list
For SuSE LINUX, the graphical interface is YaST2 and can be started with the following command
/sbin/yast2 RunLevel or click with the mouse as shown in Figure 10-2
browse:yast/?> YaST Modules?> System?> Runlevel Editor
2 turning off the GUI
Whenever possible, do not start GUI graphics on Linux server, usually on Linux server, it is not necessary to start the GUI. , all administrative tasks can be done in command line mode, or by redirecting the X and Web browser interface. There are several web-based tools available (such as Webmin, linuxconf, and SWAT).
Start the GUI when needed, and close the GUI immediately after use. In most cases, the server runs in RunLevel 3, which does not enter the GUI when the machine is booted. command-line mode, execute startx to start Xserver.
1. View RunLevel's command: RunLevel
The last and current runlevel are displayed (for example, n 5 means no last RunLevel (n), and the current runlevel is 5).
2. Switch between different runlevels, using command init
If you switch to run Level 3, type command init 3
Below is a brief description of the different runlevels in Linux
–0–halt downtime (do not set 0 to default, or the server will shut down immediately after it is started)
–1-single User Mode single
–2-multi-user Multi-user mode without NFS (if no network, quite with 3)
–3-full Multi-User mode full multi-user modes
–4–unused not used
–5-x11
–6–reboot reboot (do not set 6 to default, or the server will restart continuously)
Modify the file/etc/inittab to set the machine-initiated runlevel, such as Figure 10-3.
For SuSE LINUX Enterprise Server, execute the yast runlevel command to change the default RunLevel value.
Figure 10-2.
By default, 6 consoles are saved: F1 ... F6. To save memory, you can reduce it to 3. Implemented using the Mingetty Ttyx command, figure 10-3
Tip: Even if the GUI is turned off, you can still connect and start the GUI remotely, using Ssh-x.
3 Changing kernel parameters
The Linux kernel is the core of the operating system and is common to all Linux distributions. The kernel parameter can be changed to execute the sysctl command at the command line.
Tip: By default, the Linux kernel includes the necessary modules that do not have to be restarted to use the Sysctl command. However, if you choose to remove the feature when you install the system, you can only restart Linux to make the change take effect.
SUSE LINUX provides a way to modify the graphical interface. Use the following command to start the Powertweak tool:
/sbin/yast Powertweak
Use the following command to start the character-based administration menu:
/sbin/yast2 Powertweak
Red hat also provides a way to change the sysctl parameters under the graphical interface:
/usr/bin/redhat-config-proc
Figure 10-5:
Parameter Storage Locations
Kernel parameters are stored in/proc (especially/proc/sys), which provides parameters related to the kernel, processor, memory, network, and other components. Each executed process has a directory named after the corresponding PID. Figure 10-3 lists some of the files that include kernel information.
4 parameters of the kernel
Table 10-5 lists some kernel parameters that are closely related to the performance of Red Hat V2.4.
5 Processor Subsystem Tuning
Processors are one of the most important hardware subsystems for applications and database servers. However, in these systems, the CPU is often the bottleneck of performance.
In high-end servers with Xeon processors, you can enable or disable the hyper-threading (Hyper-Threading feature). Hyper-threading a processor into two uses in the operating system. This feature is supported by Red Hat Enterprise Linux as and SUSE Linux Enterprise Server, allowing the processor to execute two threads or processes at the same time. For hyper-threading-enabled operating systems and software, there is no need to increase the CPU clock frequency to make performance improvements significantly. For example, with the Hyper-threading feature on a 4-way server and the use of performance monitoring tools such as top to detect, you can see 8 processors. Figure 10-6
Hint, for hyper-threading:
_ Linux based on the SMP kernel can support hyper-threading
_ The more CPUs you install, the less performance you get from hyper-threading. The performance gains achieved are approximately:
–2 Physical cpu:15-25%
––4 Physical cpu:1-13%
––8 Physical cpu:0-5%
– For more information about hyper-threading, see more.
The EM64T is an 64-bit extension of the Intel IA-32 processor. This means that the processor can support more memory and support 64-bit applications while fully compatible with existing 32-bit applications. Red Hat Enterprise Linux 3 Update 2 and SUSE Linux Enterprise Server 9 support this new processor. For more EM64T information, you can see more.
Choosing the right Kernel
Red Hat Enterprise Linux as and SUSE Linux Enterprise Server include a number of kernel packages, as listed in table 10-6. Choosing the right kernel is important for performance.
6 Tuning of the memory subsystem
The tuning of the memory subsystem is not easy and needs constant monitoring to ensure that memory changes do not adversely affect other subsystems of the server. If you want to change the virtual memory parameters (in/PROC/SYS/VM), it is recommended that you change only one parameter at a time and then monitor the effect. The adjustments to virtual memory include the following items:
Configures how the Linux kernel updates dirty buffers to disk. Disk buffers are used for staging disk data. Disk buffers are slow relative to memory. Therefore, if the server uses this type of memory, performance can be problematic. When the data in the buffer is fully dirty, use: Sysctl-w vm.bdflush= "30 500 0 0 500 3000 60 20 0"
Vm.bdflush has 9 parameters, but it is recommended that you change only 3 of them:
- Nfract, maximum percentage of buffers Bdflush daemon allowed before writing to the disk
- Ndirty, the value of the maximum buffer that is written for Bdflush immediately. If this value is large, Bdflush needs more time to complete the disk's data update.
- Nfract_sync, the maximum percentage of buffer change dirty before synchronization occurs
Configuring KSWAPD daemon, specifying the number of memory Exchange pages for Linux
Sysctl-w vm.kswapd= "1024 32 64"
The three parameters are described as follows:
–tries_base corresponds to four times times the number of "pages" that the kernel swaps each time. For systems with many exchanges of information, increasing this value can improve performance.
–tries_min is the smallest number of pages that KSWAPD swaps out every time.
–swap_cluster is the number of pages inscribed as KSWAPD. Small values increase the performance of disk I/O, and large numbers can also adversely affect the request queue.
If you want to make changes to these parameters, use the tool vmstat to check the impact on performance. Other virtual memory parameters that can improve performance are:
_ Buffermem_ freepages_ overcommit_memory_ page-cluster_ pagecache_ Pagetable_cache
7 Tuning of the network subsystem
After the operating system is installed, the network subsystem should be tuned. Impact on other subsystems: affects CPU utilization, especially when there is a large number of TCP connections, block size and very small hours, memory usage will increase significantly.
How to prevent performance degradation
The SYSCTL command below is used to change security settings, but it can also prevent network performance degradation. These commands are set to the default values.
Turn off the following parameters to prevent hackers from attacking the server IP address
Turn on TCP SYN cookies to protect the server from Syn-flood attacks, including service dependent Denial-of-service (DoS) or distributed Service Denial distributed Denial-of-service (DDoS) ( Only for Red Hat Enterprise Linux as)
The following command causes the server to ignore redirects from servers that are listed on the gateway. Because redirects can be used for attacks, we only accept redirects with reliable sources.
Additionally, you can configure either to accept or reject any ICMP redirects. ICMP redirection is the mechanism by which routers transmit routing information. For example, the gateway can send redirection information to a host when the gateway receives an Internet datagram from the host network. The gateway checks the routing table for the address of the next gateway, and the second gateway routes the datagram to the destination network. The commands to close these redirects are as follows:
If the server is not a router, it does not send redirects, so you can turn off the feature:
The configuration server refuses to accept broadcast storms or Smurf attack attacks:
Ignore all ICMP packets or pings:
Some routers send an invalid response to the broadcast, each generating a warning and generating logs in the kernel. These responses can be ignored:
8. Tuning for TCP and UDP
The following command is used to tune a server with a very large number of connections.
For servers that support many connections at the same time, new connections can re-use time-wait sockets. This is very effective for Web servers:
If you use this command, you also start the time-wait socket state Fast Loop feature:
Figure 10-7 shows that these features are enabled and the number of connections is significantly reduced. Because each TCP transport contains the protocol information cache for the remote client, it helps to improve performance. The cache holds round-trip time, maximum segment size, congestion window information.
The parameter tcp_fin_timeout is the time when the socket is closed, keeping the fin-wait-2 state. A TCP connection begins with the Three-segment syn sequence and ends with the three-segment fin sequence. Data is not preserved. By changing the value of the tcp_fin_timeout, the time between the fin sequence and the memory can be idle to handle the new connection, Improve performance. Before changing this value, you should carefully monitor it to avoid memory overflow due to dead sockets.
One problem with the server is that a large number of connections are open but not in use at the same time in many TCP connections. The TCP keepalive feature detects these connections, which, by default, are discarded after 2 hours. 2 hours may lead to excessive memory usage and reduced performance. So changing to 1800 seconds (30 minutes) is a better choice:
For all protocol queues, set the maximum system send cache (WMEM) and receive cache (RMEM) to 8MB
These settings specify the amount of memory allocated to a TCP socket when it is created. In addition, use the following command to send and receive the cache. This command sets three values: Minimum, initial, and maximum values:
The third value must be less than or equal to Wmem_max and Rmem_max.
(SUSE LINUX Enterprise Server applies) validates the source packet by preserving the path. By default, the router forwards all packets, even if it is a significant exception to the network traffic. Discard these packets via the start and yes filtering function:
When the server load is heavy or there are many clients that are extremely long-delayed connection failures, the number of half-open connections can be increased. This is very common for Web servers, especially when there are many dial-up clients. These half-open connections are saved in the backlog connections queue. Set this value to a minimum of 4096 (the default is 1024). Even if the server does not receive such connections, setting this value can prevent Denial-of-service (Syn-flood) from being attacked.
Set the Ipfrag parameters, especially for NFS and samba servers. Here, we can set the maximum and minimum memory for the re-grouping of IP fragments. When the Ipfrag_high_thresh value is assigned, the fragment is discarded until the Ipfrag_low_thres value is reached.
When a TCP packet transmission error occurs, defragmentation begins. Valid packets remain in memory, while corrupted packets are forwarded. For example, set free memory range from 384 MB to
"Editor's recommendation"
- The System Performance Tuning tool under Perf event:linux
- System Performance Tuning Technology combat
- Linux system performance Tuning that thing
- Three strategies to understand Linux system performance tuning
The method of performance tuning for Linux operating system