Overview 1. "/ etc / profile" file 2. "BDFLUSH" parameter 3. "ip_local_port_range" parameter 4. "/etc/nsswitch.conf" file 5. "/ proc" file system 6. "ULIMIT" parameter 7. Increase The number of files opened by the system 8. File "ATIME" attribute 9. The "noAtime" property of the file 10. Specific TCP / IP Stack 11. Switch partition 12. Adjust the IDE hard disk performance overview Optimized network performance to a large extent to the network Software and hardware is used. How to optimize the network is difficult to use a book to be clear. It is difficult to know the bottleneck of the network before the network is really running. Performance optimization is not very simple and intuitive, must be used as a very complex task. Moreover, not only many constraints need to be highly accurate. Unless specifically testing the bottleneck in the diagnostic system, it is difficult to explain. Sometimes performance optimization will become a very disappointing and tedious work, especially when the results obtained after a lot of analysis are still unsure. However, the optimization of system performance is a very return work and will bring long-term benefits to the entire system. 1. The "/ etc / profile" file "etc / profile" file contains a large environment and the configuration information of the launcher. The configuration you are in this file can be implemented by applying for a global environment variable. Therefore, setting optimization marks in this file is a wise choice. To make the X86 program to get the best performance, you can use the best optimized option -O9 when compiling. The "Makefile" file in many programs has already contained -O2 options, while -O9 enables the compiler to adopt the highest level optimization. Although it will increase the size of the final program, this can achieve a higher running speed. When compiling, use the "-Fomit-Frame-Pointer" option, the program is run when the program is running, and the stack will be used. However, using this option, the code produced will not be debugged. With the "-MCPU = CPU_TYPE" and "-March = CPU_TYPE" option, GCC will specifically optimize this model CPU, but the generated code can only be run on the specified CPU or higher series of CPUs.
For CPU i686 or PentiumPro, Pentium II, Pentium III in the "/ etc / profile" file, add a line: cflags = '- o9 -funroll-loops -ffast-math-malign-double -mcpu = pentiumpro-march = pentiumpro - Fomit-frame-pointer -fno-exceptions 'For CPU I586 or Pentium, add a line in the "etc / profile" file: cflags =' - o3 -MARCH = Pentium -MCPU = Pentium -ffast-Math -Funroll-loops -Fomit -FRAME-POINTER -FFORCE-MEM -FFORCE-AddR-Malign-Double -Fno-Exceptions 'For CPU I486 in the "etc / profile" file, join a line: cflags =' - o3 -funroll-all-loops -malign- Double-MCPU = i486 -March = i486 -Fomit-frame-pointer -fno-exceptions' After completing the above setting, the next person adds "cflags lang lesscharset" to "export" in the "etc / profile" file. Line: Export Path PS1 Hostname HistSize HistFileSize User Logname Mail Input, then log in, then, the environment variable CFLAGS has been assigned, the compiler, and other configuration tools can use it. Optimization of Pentium (Pro / II / III) must use the EGCS or PGCC compiler. In the default installation of Linux, EGCs has been installed, so there is no need to worry. Benchmark results (classification by architecture): Optimization options will be different due to the different version of the CPU's architecture and the version of GCC / EGCs used. The following chart can help you select the best compile option based on your own CPU and compiler. The version of the compiler installed in Redhat 6.1 is EGCS 2.91.66, but even if you installed Redhat 6.1, be sure to check the compiler before selecting the Compile Option. To confirm the version of the compiler, use the following command: [root @ deep] # EGCS --Version. Note: All test results can be retrieved from the homepage of GCC: http://egcs.cygnus.com/.
Examples: For CPU Pentium II / III (i686), the best compilation option is: cflags = '- o9 -funroll-loops -ffast-math-malign-double -mcpu = PentiumPro -March = PentiumPro -FOMIT-FRAME-POINTIUMPRO-EXCEPTIONS 'For CPU Pentium (I586), the best compilation option is: cflags =' - o3-march = pentium -mcpu = Pentium -ffast-math -funroll-loops -fomit-frame-pipe -force-mat -force-addr-malign-double -fno-exceptions' For CPU I486, the best compilation option is: Cflags = '- o3 -funroll-all-loops -malign-double -mcpu = i486 -March = i486 -FOTIMIT-FRAME-POINTER -FNO-Exceptions'-Funroll-loops Options Optimize "loop unrolling", only The cycle statement determined by compilation or runtime cycle is valid. -funroll-all-loops Optimize "Loop Unrolling", which is valid for all cyclic statements, and the unit is usually slowed down. -ffast-math This option allows GCC to fail to follow the ANSI or IEEE rules to get running faster optimization code. For example: it allows the compiler to assume that the input parameters of the SQRT () function are non-negative and all floating point numbers are Nans. -malign-doublegcc The Double, Long Double, and long long type variable is controlled by this option on a double word or a single-word boundary. Double type variables are bound to the double word boundary, generated code can run faster on the Pentium machine, but will take up more memory. -mcpu = CPU_TYPE Sets the default machine and CPU type when the instruction is generated, and after setting a particular CPU type, the compiler will generate the corresponding instructions for this chip, if not "-March = CPU_TYPE" Options, the compiler does not generate any code that cannot be run on I386. "I586" is equivalent to "Pentium", "I686" equivalent to "PentiumPro", "K6" indicates that the AMD chip is used instead of the Intel series. -march = CPU_TYPE creates an instruction for the machine and CPU of the specified type. The CPU type here is the same as those listed in "-mcpu". Moreover, using this option already implies the "-mcpu = CPU_TYPE" option. -FFORCE-MEM For operation involving memory operations, copy the operand to the register. This is to achieve optimized code by converting all memory references into potential ordinary sub-expressions. If these memory references are not ordinary sub-expression, the individual registers load can be eliminated by a combination of instructions. The -fforce-addr is copied to the register before the operation of the -force-addr. The resulting optimization code is similar to the option "-fforce-mem". -FOTIMIT-FRAME-POINTER is not saved in the register for unnecessary frame pointers. This avoids the corresponding instructions required for saving, setting, and recovering the frame pointer; this, additional registers can be used in many functions. However, this option makes it unable to debug in most machines.
Note: All optimizations that this book will be discussed, the default is for the Pentium II / III series CPU. Therefore, if necessary, adjust the compilation parameters for some special CPUs. 2. "BDFLUSH" parameter discusses the system control file under the directory "/ proc / sys / vm" and is only valid under Linux core version 2.2. Control the file in this directory, you can adjust the behavior of Linux kernel (VM) in the Linux kernel (VM), where the BDFlush file has a certain impact on the hard disk. This file controls the behavior of the BDFLUSH core daemon. We usually use the following command to improve the performance of the file system: Echo "100 1200 128 512 15 5000 500 1884 2"> / Proc / Sys / VM / BDFLUSH Modify certain values, allowing system response faster, for example: Wait a longer time before writing the hard disk, thereby avoiding the conflicts of some hard disk access. Add this command to the file "etc / rc.d / rc.local", when you restart your machine, you don't have to manually knock this command again. If you need to further understand how to improve kernel parameters for virtual memory, hard disk buffer, and swap space (SWAP), you can refer to "/usR/src/linux/documentation/sysctl/vm.txt". 3. "IP_LOCAL_PORT_RANGE" parameter discusses the system control file under the directory "/ procal_port_range", and only valid under Linux kernel version 2.2. Two parameters in the "IP_LOCAL_PORT_RANGE" file define port ranges used as TCP and UDP local ports, respectively. The first parameter is the first port number. The second parameter is the last local port number. For systems with high usage, you can modify: 32768 to 61000. Echo * 32768 61000 *> / proc / sys / net / ipv4 / ip_local_port_range The command adds the command "/etc/rc.d/rc.local", do not have to manually hit this time each time you restart The order is commanded. 4. The "/etc/nsswitch.conf" file "etc / nsswitch.conf" file defines which services used to resolve the host name, get the password file, and group files (Group file). In our system, because there is no NIS service, there is no use of the password file and group file. Here, we only discuss this line in this document. Edit the "nsswitch.conf" file (vi /etc/nsswitch.conf), change the Host line to: "Hosts: DNS file" meaning: When requesting the resolution address, first access the DNS server, if the DNS server does not respond, then use "/ Etc / hosts" file. I recommend deleting NIS in each line of the file. Of course, if you have to use NIS, you can't delete NIS. Finally, the file would be like this: passwd: filesshadow: filesgroup: fileshosts: dns filesbootparams: filesethers: filesnetmasks: filesnetworks: filesprotocols: filesrpc: filesservices: filesautomount: filesaliases:. Files5 "/ proc" filesystem discussed below directory "proc / sys The system control file under / fs is only valid under Linux core version 2.2. The files in this directory can be used to adjust and monitor some behaviors of the Linux kernel.
The misoperation of these files may be disturbed, so before the system is actually adjusted, it is best to read the document and source code. Appropriate increase in "/ proc / sys / fs / file-max: every 4m
Memory corresponds to 256, for example: memory is
128M
The machine can be set to 8192 (128/4 = 32 32 * 256 = 8192). Similarly, the value of "/ proc / sys / fs / inode-max" can be added to the value of 3 to 4 times the number of open files (8192 * 4 = 32768). This is because: the number of nodes is at least equal to the number of open files, in general, for large files, the number of nodes is much larger than the number of open files. The common command for changing / proc directory and any parameters in its subdirectory is (must log in to root): echo "New Parameter Value"> "/ proc / required file", for the modifications mentioned above Its commands are: Echo "8192"> / proc / sys / fs / file-maxecho "32768"> / proc / sys / fs / inode-max discussed above, modified the constant of the kernel source code. However, it does not work in the new kernel source code tree, so it is not possible to be the best way. The best way is to add the above command to the file "etc / rc.d / rc.local". At the end of the file, add the following two lines (assuming the system has
128M
Memory): Echo "8192"> / proc / sys / fs / file-max echo "32768"> / proc / sys / fs / inode-max, which is different from the system, the difference is very large, should be based on the respective systems The above formula is calculated. The number of files that requires a file server or web server is very large, and the value used for values is smaller. For systems that have many memory, especially
512M
Or more memory system, the number of open files and i nodes is preferably not more than 50,000 and 150,000. The "file-max" parameter refers to the maximum number of file handles that Linux kernels can be assigned. When the system often reports: When the file handle is not enough, the value of this parameter needs to be appropriately increased. The system default is: 4096. "Inode-Max" parameter refers to the maximum number of system i node handles. Its value should be 3 to 4 times the File-Max value. Because the standard input and output files and network sockets use I nodes to process. If the i node is exhausted, it is necessary to increase its value. 6. "ulimit" parameter Linux is limited to the number of maximum processes owned by each user. This limitation can be added in the ".bashrc" file in the user's root directory or actually uses the ".bashrc" Skell's script. Edit the ".bashrc" file (for example: vi /root/.bashrc) and add the following line: ulimit -u unlimited then exit, log in again. To verify, you can log in as root, then type: "ulimit -a", "unlimited" should be displayed in the maximum number of user processes, such as [root @ deep] # ulimit -acore file size (block) 1000000Data Seg size (kbytes) unlimitedfile size (blocks) unlimitedmax memory size (kbytes) unlimitedstack size (kbytes) 8192cpu time (seconds) unlimitedmax user processes unlimited * this line.pipe size (512 bytes) 8open files 1024virtual memory (kbytes) 2105343 Note: you May be more inclined to type "unlimit -u" instead of the command line instead of adding it to the file "/ ROOT /.BASHRC". But for the insurance, it is recommended to add it to the file "/Root/.bashrc". 7. Increase the number of files opened by the system 8. File "atime" attribute 9. Document "NoAtime" attribute 10. Specific TCP / IP Stack 11. Exchange Partition 12. Adjust IDE Hard Disk Performance 7. Adding the number of files opened by the system The current process opens the number of files. Redhat 6.0 (Core 2.2.5
In this way, this method process can open at least 31,000 file descriptors; the kernel version is 2.2.12, at least 90,000 file descriptors (under appropriate limitations). Its upper limit is limited only to available memory. Edit the ".bashrc" file (for example: vi /root/.bashrc) and add the following line: Ulimit -N 90000 then exit, log in. To verify, you can log in as root, then type "Ulimit -a", "90000" should be displayed in the Open File, for example: [root @ deep] # ulimit -acore file size (blocks) 1000000Data seg size kbytes) unlimitedfile size (blocks) unlimitedmax memory size (kbytes) unlimitedstack size (kbytes) 8192cpu time (seconds) unlimitedmax user processes unlimitedpipe size (512 bytes) 8open files 90000 * this line.virtual memory (kbytes) 2105343 NOTE: in earlier In the 2.2 version of the kernel system, even if the above modification is performed, the number of files that can be opened each process is still limited to 1024.8. File "Atime" Property Linux Record files in addition to the creation and modification time of the record file interview time. This information is not large, but for retaining it, the system needs to consume corresponding resources. The EXT2 file system allows the super user to mark a single file to ignore the record of this information. This optimization adjustment is significantly improved for file search operations, and system performance is improved, and it is also useful for files that require regular access (such as / var / spool / news). Setting this property to: [root @ deep] # chattr a filename If you need this setting to all files in a directory, you can use: [root @ deep / root] # chattr -r a / var / spool / [root @ Deep / root] # chattr -r a / cache / [root @ deep / root] # chattr -r a / home / httpd / ona / 9 "noarative" property Linux in MOTINT When a file system is used, you can use the "NoAtime" option. And you can join in the Mount option area of the file "/ etc / fstab". When the file system containing this option is hanging into the (Mount) system, the ATIME information of the file in the file system is not updated. Under normal circumstances, the ATIME information is useless, so it is not a case without updating the domain. The importance of this option is that when only the file reads the file, it is no longer necessary to write information to the corresponding area of the file in the file system. Because the cost of writing operation is expensive, this option can achieve significant performance improvement. This option has no effect on the WTIME property of the file, and the file's WTIME information is updated each time the file is written.
Edit the "FSTAB" file (VI / etc / fstab) and join the following line (illustrated): EX: / dev / sda7 / chroot ext2 defaults, noarative 1 2 Restart the system, then use the following command test: [root @ deep ] # reboot [root @ deep] # cat / proc / mounts10. Specific TCP / IP stack Redhat Linux, in general, does not optimize TCP / IP window size. This can make system performance differences. For more information, see: RFC 1106 - High Latency Wan Links - Section 4.1 And RFC 793 - Transmission Control Protocol. Edit file "/ etc / sysconfig / network-scripts / iFUP", lines 110, 112, 117, 125 and 134,: 110: "Route Add -net $ {network} $ {device}" 112: "Route add -host $ {ipaddr} $ {device}" 117: "Route Add Default GW $ {GATEWAY} metric 1 $ {device}" 125: "Route Add Default GW $ {Gateway} $ {device}" 134: "Route Add Default GW $ GW $ {Device}" modified to: 110: "Route add -net $ {network} netmask $ {netmask} Window 8192 $ {device}" 112: "Route Add -host $ {ipaddr WINDOW 8192 $ {device} 117: "Route Add Default GW $ {Gateway} WINDOW 8192 Metric 1 $ {device}" 125: "Route Add Default GW $ {Gateway} Window 8192 $ {device}" 134: "ROUTE Add Default GW $ GW WINDOW 8192 $ {device} "11. Exchange partitions as far as possible to place the swap partition on the start area of the hard disk. The start area of the hard disk is physically located outside the outer ring portion of the hard disk cylinder, so every revolution of the hard disk will read more information in this part. I have seen that when running the command "hdparm -t", put the exchange partition on the end of the hard disk, and the system's read and write speed is 3MB / s low in the start of the hard disk. 12. Adjust the IDE hard disk performance When there is a large amount of disk I / O operation, set the IDE hard drive to use the DMA, 32-bit transfer and multiple sector modes (Multiple Sector Mode), which can greatly improve system performance. Unless explicitly telling the kernel to use these modes, the kernel default is to use conservative settings. Use the following command to allow the PCI bus to allow 32-bit I / O operations: [Root @ deep] # / sbin / hdparm -c 1 / dev / hda (or HDB, HDC, etc.) HDPARM (8) Help information (MANPAGE The description is described: "-c3" is used for some chips
. All (e) IDE hard drives are connected to a 16-bit connection in a flat cable connected to the interface card. Use the following command to allow DMA way: [root @ deep] # / sbin / hdparm -d 1 / dev / hda (or HDB, HDC, etc.) This depends on the motherboard chipset selected when the core is compiled. Use the following command to allow multiple words of DMA mode 2 to transfer: [root @ deep] # / sbin / hdparm -d 1-x34 / dev / hda (or HDB, HDC, etc.) This is a newer (e) IDE / ATA2 Hard Disk Sets the transfer mode of the IDE. (Refer to the hard disk manual to verify that your hard disk supports this mode) Use the following command to allow Ultradma mode 2: [root @ deep] # / sbin / hdparm -d 1 -X66 / dev / hda (or HDB, HDC) Wait, before using this command, you should have a chipset that supports Ultradma, and see HDPARM's help information. Be careful when using this command. Use the following command to allow multiple sectors I / O mode: [root @ deep] # / sbin / hdparm -m xx / dev / hda (or HDB, HDC, etc.) where the parameter XX refers to the maximum use of hard disk support. Set. You can use the "-i" option to move the maximum setting supported by the hard drive. You can view the value of MaxMultsect in the output. For example: [root @ deep] # / sbin / hdparm -i / dev / hda (or HDB, HDC, etc.) / dev / hda: model = maxtor 7540 av, fwrev = ga7x4647, serialno = l1007yzsconfig = {Hardsect Notmfm HDSW> 15uSec Fixed DTR> 5Mbs FmtGapReq} RawCHS = 1046/16/63, TrkSize = 0, SectSize = 0, ECCbytes = 11BuffType = 3 (DualPortCache), BuffSize = 32kB, MaxMultSect = 8, MultSect = 8DblWordIO = yes, maxPIO = 2 ( FAST, DMA = YES, MAXDMA = 1 (Medium) curchs = 523/32/63, CURSECTS = 379584528, LBA = YES, LBA = YES, LBA = 1054368TDMA = {min: 150, REC: 150}, DMA MODES: Sword0 Sword1 * Sword2 * mword0iordy = ON / OFF, TPIO = {Min: 240, W / IRDY: 180}, Pio Modes: Mode3 Most hard drives support multi-zone mode (Multiple Sector Mode or Aka IDE Block Mode, it allows multiple sectors to transmit multiple sectors in one interrupt instead of interrupt to transfer one sector. A hard drive with this feature allows the operating system to drop by 30-50% in the hard disk I / O. In many systems, it can improve the throughput rate of 5-50%. You can use HDPARM test mode to test the result of modified results: [Root @ Deep] # / sbin / hdparm -t / dev / hda (or HDB, HDC, etc.) After the above modification, don't forget to join them In the file "/etc/rc.d/rc.local", it is possible to automatically run each restart system.