Reprinted: http://www.517sou.net/Article/104.aspx
I. Factors affecting Linux server performance
1. Operating System Level
CPU
Ø memory
Ø disk I/O bandwidth
Ø network I/O bandwidth
2. Application-level
Ii. System Performance Evaluation Criteria
Performance Impact Factors
Criteria
Good
Bad
Bad
CPU
USER % + sys % <70%
User %+ sys % = 85%
USER % + sys %> = 90%
Memory
Swap in (SI) = 0
Swap out (SO) = 0
Per CPU with 10 page/s
More swap in & swap out
Disk
Iowait %< 20%
Iowait %= 35%
Iowait % >= 50%
Where:
% USER: the percentage of time when the CPU is in user mode.
% SYS: the percentage of time when the CPU is in system mode.
% Iowait: Percentage of CPU waiting for input/output completion time.
Swap in: Si, indicating page import of virtual memory, that is, switching from swap disk to ram
Swap out: So indicates page export of the virtual memory, that is, switching from Ram to swap disk.
Iii. System Performance Analysis Tools
1. Common system commands
Vmstat, SAR, iostat, netstat, free, PS, top, etc.
2. Common combination methods
• Use vmstat, SAR, and iostat to detect CPU bottlenecks
• Use free and vmstat to detect memory bottlenecks
• Use iostat to check whether it is a disk I/O bottleneck
• Use netstat to detect network bandwidth bottlenecks
Iv. Linux Performance Evaluation and Optimization
1. Overall system performance evaluation (uptime command)
[Root @ web1 ~] # Uptime
16:38:00 up 118 days, 5 Users, load average: 1.22, 1.02, 0.91
Note: Load average is the output value. The size of these three values cannot be greater than the number of system CPUs. For example, the system has eight CPUs in this output, if the three load average values are greater than 8 for a long time, the CPU is very busy and the load is high, which may affect the system performance, generally, the system performance is not affected. On the contrary, if the output value of load average is smaller than the number of CPUs, it indicates that the CPU has idle time slice. For example, the output in this example, the CPU is very idle.
2. CPU Performance Evaluation
(1) Monitor the CPU of the system using the vmstat command
This command displays brief information about the performance of various system resources. Here we mainly use it to view a CPU load.
The output result of the vmstat command in a system is as follows:
[Root @ node1 ~] # Vmstat 2 3
Procs ----------- memory ---------- --- swap -- ----- Io ---- System -- ----- CPU ------
R B SWPD free buff cache Si so Bi Bo in CS us Sy ID wa st
0 0 0 162240 8304 67032 0 13 21 1007 23 0 1 98 0 0
0 0 0 162240 8304 0 0 1 0 67032 20 0 1 1010 0
0 0 0 162240 8304 67032 0 1 1 1009 18 0 1 99 0 0
L procs
The r column indicates the number of processes that run and wait for the CPU time slice. If the value is greater than the number of CPU for a long time, the CPU is insufficient and the CPU needs to be increased.
Column B indicates the number of processes waiting for resources, such as waiting for I/O or memory switching.
L CPU
The US column shows the percentage of CPU time consumed by the user process. When the value of us is high, it indicates that the user process consumes a lot of CPU time. However, if it is longer than 50%, you need to consider the optimization program or algorithm.
The Sy column shows the percentage of CPU time consumed by kernel processes. When the SY value is high, it indicates that the kernel consumes a lot of CPU resources.
Based on experience, the reference value of US + Sy is 80%. If the value of US + Sy is greater than 80%, there may be insufficient CPU resources.
(2) monitoring system CPU using SAR commands
The SAR function is very powerful and can be used for separate statistics on every aspect of the system. However, using the sar command will increase the system overhead, but these overhead can be evaluated, the system's statistical results will not be greatly affected.
The following figure shows the CPU statistics output of a system by using the sar command:
[Root @ webserver ~] # Sar-U 3 5
Linux 2.6.9-42. elsmp (webserver) 11/28/2008 _ i686 _ (8 CPU)
11:41:24 am CPU % USER % nice % System % iowait % steal % idle
11:41:27 am all 0.88 0.00 0.29 0.00 0.00 98.83
11:41:30 am all 0.13 0.00 0.17 0.21 0.00 99.50
11:41:33 am all 0.04 0.00 0.04 0.00 0.00 99.92
11:41:36 am all 90.08 0.00 0.13 0.16 0.00 9.63
11:41:39 am all 0.38 0.00 0.17 0.04 0.00 99.41
Average: All 0.34 0.00 0.16 0.05 0.00
The output of each item is described as follows:
The l % USER column shows the percentage of CPU time consumed by user processes.
The l % nice column shows the percentage of CPU time consumed by normal processes.
The l % system column shows the percentage of CPU time consumed by system processes.
L % iowait column displays the percentage of CPU time occupied by Io wait
The l % steal column displays the steal operations that pagein forces on different pages in a memory-intensive environment.
The l % idle column shows the percentage of time when the CPU is idle.
Problem
1. Have you ever encountered a problem where the overall CPU usage is not high and applications are slow?
In a multi-CPU system, if the program uses a single thread, the overall CPU usage is not high, but the system application responds slowly, this may be because the program uses a single thread. A single thread uses only one CPU, resulting in a CPU usage of 100%. Other requests cannot be processed, but other CPUs are idle, this results in low overall CPU usage and slow application.
3. Memory Performance Evaluation
(1) monitor memory with free commands
Free is the most common command to monitor Linux memory usage. See the following output:
[Root @ webserver ~] # Free-m
Total used free shared buffers cached
Mem: 8111 7185 926 0 243 6299
-/+ Buffers/cache: 643 7468
Swap: 8189 0 8189
Generally, an empirical formula is as follows: when the memory available for an application/the physical memory of the system is greater than 70%, the system memory resources are very sufficient and the system performance is not affected, when the application memory available/system physical memory <20%, it indicates that the system memory resources are insufficient and the system memory needs to be increased by 20% <application memory available/system physical memory <70%, it indicates that the system memory resources can basically meet the application requirements and does not affect the system performance.
3. Memory Performance Evaluation
(1) monitor memory with free commands
Free is the most common command to monitor Linux memory usage. See the following output:
[Root @ webserver ~] # Free-m
Total used free shared buffers cached
Mem: 8111 7185 926 0 243 6299
-/+ Buffers/cache: 643 7468
Swap: 8189 0 8189
Generally, an empirical formula is as follows: when the memory available for an application/the physical memory of the system is greater than 70%, the system memory resources are very sufficient and the system performance is not affected, when the application memory available/system physical memory <20%, it indicates that the system memory resources are insufficient and the system memory needs to be increased by 20% <application memory available/system physical memory <70%, it indicates that the system memory resources can basically meet the application requirements and does not affect the system performance.
(2) monitor memory using the vmstat command
[Root @ node1 ~] # Vmstat 2 3
Procs ----------- memory ---------- --- swap -- ----- Io ---- System -- ----- CPU ------
R B SWPD free buff cache Si so Bi Bo in CS us Sy ID wa st
0 0 0 162240 8304 67032 0 13 21 1007 23 0 1 98 0 0
0 0 0 162240 8304 0 0 1 0 67032 20 0 1 1010 0
0 0 0 162240 8304 67032 0 1 1 1009 18 0 1 99 0 0
L memory
The SWPD column indicates the number of memories switched to the memory swap zone (in K ). If the value of SWPD is not 0, or it is relatively large, as long as the value of Si and so is 0 for a long time, do not worry about this situation, it will not affect the system performance.
The free column indicates the number of idle physical memory (in K)
The buff column indicates the amount of memory in the buffers cache. Generally, the buffer is required for reading and writing Block devices.
The cache column indicates the memory size of page cached. It is generally used as the file system cached. files that are frequently accessed will be cached. If the cache value is large, it indicates that there are many cached files, if the Bi in I/O is relatively small at this time, the file system is more efficient.
L swap
The SI column indicates the amount of memory transferred from the disk to the memory swap zone.
The so column indicates the amount of memory transferred from the memory to the disk, that is, the number of memories in the memory swap zone.
Generally, the SI and so values are 0. If the Si and so values are not 0 for a long time, the system memory is insufficient. You need to increase the system memory.
4. Disk I/O performance evaluation
(1) Basic disk storage
L familiar with RAID storage methods. You can select different raid methods based on different applications.
L try to replace direct disk I/O with memory read/write, so that frequently accessed files or data are put into the memory for operation, because memory read/write operations are times more efficient than direct disk read/write operations.
L separate the files that are frequently read and written from those that are permanently unchanged and place them on different disk devices.
L for data with frequent write operations, you can consider replacing the file system with bare devices.
Advantages of using bare devices include:
Ü data can be read and written directly without being cached by the operating system. This saves memory resources and avoids memory resource contention.
Ü avoids the file system maintenance overhead, such as the need to maintain Super blocks and I-node for the file system.
Ü avoids the cache pre-read function of the operating system and reduces I/O requests.
The disadvantage of using bare devices is:
Ü data management and space management are not flexible and must be operated by a professional.
(2) Evaluate disk performance using iostat
[Root @ webserver ~] # Iostat-D 2 3
Linux 2.6.9-42. elsmp (webserver) 12/01/2008 _ i686 _ (8 CPU)
Device: TPS blk_read/s blk_wrtn/s blk_read blk_wrtn
SDA 1.87 2.58 114.12 6479462 286537372
Device: TPS blk_read/s blk_wrtn/s blk_read blk_wrtn
SDA 0.00 0.00 0.00 0 0
Device: TPS blk_read/s blk_wrtn/s blk_read blk_wrtn
SDA 1.00 0.00 12.00 0 24
The output of each item is described as follows:
Blk_read/s indicates the number of data blocks read per second.
Blk_wrtn/s indicates the number of data blocks written per second.
Blk_read indicates the number of all read blocks.
Blk_wrtn indicates the number of all written blocks.
You can use the values of blk_read/s and blk_wrtn/s to have a basic understanding of the disk's read/write performance. If the value of blk_wrtn/s is large, it indicates that disk write operations are frequent, you can consider optimizing the disk or optimization program. If the blk_read/s value is large, it means that the disk has a lot of Direct Read operations. You can put the read data into the memory for operations.
The values of these two options do not have a fixed size. Different values vary depending on the system application. However, there is a rule that can be followed: long-running and ultra-large data reads and writes are definitely not normal. This situation will definitely affect the system performance.
(3) Evaluating disk performance using SAR
Using the "SAR-d" combination, you can make a basic statistics on the System Disk Io. See the following output:
[Root @ webserver ~] # Sar-D 2 3
Linux 2.6.9-42. elsmp (webserver) 11/30/2008 _ i686 _ (8 CPU)
11:09:33 Dev TPS rd_sec/s wr_sec/s avgrq-SZ avgqu-SZ await svctm % util
11:09:35 dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
11:09:35 Dev TPS rd_sec/s wr_sec/s avgrq-SZ avgqu-SZ await svctm % util
11:09:37 dev8-0 1.00 0.00 12.00 12.00 0.00 0.00 0.00 0.00
11:09:37 Dev TPS rd_sec/s wr_sec/s avgrq-SZ avgqu-SZ await svctm % util
11:09:39 dev8-0 1.99 0.00 47.76 24.00 0.00 0.50 0.25 0.05
Average: Dev TPS rd_sec/s wr_sec/s avgrq-SZ avgqu-SZ await svctm % util
Average: dev8-0 1.00 0.00 19.97 20.00 0.00 0.33 0.17 0.02
Meanings of the following parameters:
Await indicates the average wait time (in milliseconds) for each device I/O operation ).
Svctm indicates the average service time (in milliseconds) for each device I/O operation ).
% Util indicates a fraction of the time in one second for I/O operations.
The following criteria are generally used to judge disk I/O performance:
Under normal circumstances, the svctm should be smaller than the await value, while the svctm size is related to the disk performance. The CPU and memory load will also affect the svctm value, too many requests indirectly increase the svctm value.
The size of the await value generally depends on the svctm value, the length of the I/O queue, and the I/O Request mode. If the svctm value is close to that of await, there is almost no I/O wait, disk performance is good. If the await value is much higher than the svctm value, it means that the I/O queue waits too long and the applications running on the system will slow down, at this time, you can solve the problem by replacing the faster hard disk.
The value of % util is also an important indicator for measuring disk I/O. If % util is close to 100%, it indicates that the disk has too many I/O requests, the I/O system is working at full capacity, and the disk may have a bottleneck. In the long run, the system performance will inevitably be affected. You can solve this problem by optimizing the program or replacing a higher or faster disk.
5. Network Performance Evaluation
(1) ping the command to check network connectivity
(2) detect network interface status through netstat-I combination
(3) detect the system's route table information through the netstat-r combination
(4) display the network running status of the system through the SAR-N combination
V. Oracle Performance Optimization in Linux
Optimization of Oracle Database memory Parameters
Oracle-related system kernel parameters
Ø SGA and PGA parameter settings
Oracle disk storage performance optimization
Ø File System Selection (ext2/ext3, XFS, ocfs2)
Oracle ASM Storage
1. What should I know before optimizing Oracle performance parameters?
1) physical memory size
2) How much memory should be used by the operating system?
3) whether the database uses a file system or a bare Device
4) number of concurrent connections
5) whether the application is of the OLTP or OLAP type
2. Optimization of Oracle Database memory Parameters
(1) System Kernel Parameters
Modify the/etc/sysctl. conf file and add the following statement:
Kernel. shmmax = 2147483648
Kernel. shmmni = 4096
Kernel. Shmall = 2097152
Kernel. SEM = 250 32000 100 128
FS. File-max = 65536
Net. ipv4.ip _ local_port_range = 1024 65000
The parameters are as follows:
Kernel. shmmax: the maximum size (in bytes) of the shared memory segment ).
Kernel. shmmni: Maximum number of shared memory segments in the system.
Kernel. Shmall: Total shared memory, in pages.
FS. File-MAX: number of file handles, indicating the number of files that can be opened in Linux.
Net. ipv4.ip _ local_port_range: IPv4 port range that can be used by the application.
Several Notes
About kernel. shmmax
Oracle SGA is composed of shared memory. If the shmmax setting is incorrect, it may limit the size of the SGA, and insufficient shmmax settings may cause the following problems: ORA-27123: Unable to attach to shared memory segment, if this parameter is smaller than the Oracle SGA setting, SGA will be allocated with multiple shared memory segments. This may be a performance burden in a busy system and cause system problems.
Oracle recommends that kernel. shmmax be better than SGA to make the Oracle shared memory SGA in a shared memory segment to improve performance.
About kernel. Shmall
The total size of the system shared memory, in pages.
A 32-bit Linux system with 8 GB memory can be configured with kernel. shmall = 2097152, that is: 2097152*4 K/1024/1024 = 8g, that is, a total of 8 GB of available shared memory, here 4 k is the size of a 32-bit operating system page, that is, 4096 bytes.
About kernel. shmmni
The maximum number of shared memory segments in the system. The default value is 4096, which generally does not need to be modified. There is also the kernel. shmmin parameter in Sun OS, which indicates the minimum size of the shared memory segment. Do not mix shards!
(2) SGA and PAG parameter settings
A Oracle memory management improvements
Oracle 9i uses the pga_aggregate_target parameter to implement automatic PGA Management of Oracle 10 Gb. The sga_target parameter implements automatic SGA management,
Oracle 11g Enables automatic management of all memory blocks of the database, making dynamic management of SGA and PGA a reality.
Two Parameters for Automatic Memory Management:
Memory_target: memory size available for the entire Oracle instance, including the overall size of PGA and SGA. this parameter is dynamic and can be used to dynamically control the size of SGA and PGA.
Memory_max_target: this parameter defines the maximum value of memory_target that can be reached without restarting the instance. If the memory_max_target value is not set, it is equal to the value of memory_target by default.
When dynamic memory management is used, sga_target and pga_aggregate_target represent the minimum settings of their respective memory regions. To allow Oracle to fully control memory management, these two parameters should be set to 0.
Five memory management methods of B Oracle
Ø Automatic Memory Management (AMM)
Ø automatic shared memory management, that is, asmm (automatic shared memory management)
Ø manual shared memory management
Automated PGA Management
Ø manual PGA Management
Automatic Memory Management (AMM)
By default, the instance with oracle11g installed is AMM. View the information as follows:
Example:
SQL> show parameters target
Name type value
------------ --------------------- ------------------ ------------------------ Archive_lag_target integer 0
Db_flashback_retention_target integer 1860
Fast_start_io_target integer 0
Fast_start_mttr_target integer 0
Memory_max_target big integer 1400 m
Memory_target big integer 1400 m
Pga_aggregate_target big integer 0
Sga_target big integer 0
Note: If the initialization parameter lock_sga = true, AMM is unavailable.
Automatic shared memory management
Automatic shared memory management is introduced in Oracle10g. To use automatic shared memory management, you only need to set memory_target = 0 and then explicitly specify sga_target.
Example:
SQL> alter system set memory_target = 0 scope = both;
System altered.
SQL> alter system set sga_target = 1024 M scope = both;
System altered.
SQL>
Manual shared memory management
For Oracle9i and earlier versions, you can only manually set shared memory management. To use manual shared memory management, you must first set sga_target and memory_target to 0.
The main parameters of SGA include:
Share_pool_size: size of the Shared Pool. the recommended size is between-MB.
Log_buffer: the size of the log buffer. It is recommended to be 1-3 m.
Large_pool_size: large buffer pool size. It is not a MTS system. It is recommended to be between 20-30 m.
Java_pool_size: Java pool size. It is recommended that the size be between 10-20 mb if no Java application is available.
Db_cache_size: data buffer size, which is as large as possible based on the available memory size.
Automatic PAG Management
In Oracle9i, automatic PGA management is introduced. If you are using the AMM management method, you do not need to worry about the configuration of PGA. However, if you are not worried about the management of AMM, you can set Automatic PGA management and settings.
Workarea_size_policy = auto
Then, specify the pga_aggregate_target size .,
Manual PAG Management
If you want to precisely control the PGA, you can also set the settings to manually manage the PGA.
Workarea_size_policy = manual
Then specify the PGA parameters:
PGA-related parameters include:
Sort_area_size
Sort_area_retained_size,
3. Oracle disk storage performance optimization
① Select a file system to access data
File System Selection
Single file system (ext2, ext3, XFS, etc)
Cluster File System (GFS, ocfs2)
Advantages and disadvantages of file system storage:
Advantage: convenient management and maintenance.
Disadvantage: Data Reading and Writing must go through the operating system-level cache, and the efficiency is not very high.
② ASM (Automatic Storage Management)
Advantages of ASM:
Data can be directly read and written without passing through the operating system. The read and write efficiency is basically the same as that of the original device.
Oracle provides dedicated management and maintenance tools
About the author
Gao Junfeng, network name: South African ant
Ixpub "storage device and Disaster Tolerance Technology" and "Linux and Open Source World" moderators.
Like Oracle and Unix/Linux technologies, the main activities in the itpub.net, ixpub.net, chinaunix.net and other large technical communities have been committed to Oracle database, Unix/Linux operating system management, optimization, currently, we are mainly engaged in Oracle database management and project planning and design. We are good at Oracle database backup and recovery, performance tuning, and some research on Unix/Linux cluster applications.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/eroswang/archive/2011/04/12/6318777.aspx