Linux server performance Analysis and optimization

Source: Internet
Author: User
Tags server memory

#1 View Hardware product names
Dmidecode |grep ' Product Name '

#2 View the motherboard serial number
Dmidecode |grep-i ' serial number ' |grep CN

#3 View CPU Models
grep name/proc/cpuinfo

#4 See the number of CPUs (cores):
grep ' physical ID '/proc/cpuinfo

#5 View CPU Usage
Top

#6 View memory Information
grep memtotal/proc/meminfo
Free-m
Vmstat

#7 View the size of a partition
Fdisk-l

#8 View Partition Usage
Df-h

#9 View Kernel version
Cat/etc/redhat-release
Cat/etc/issue
Uname-rm

#10 Viewing system Boot Information
DMESG |grep SDA

#11 viewing individual device interrupt requests (IRQ)
Cat/proc/interrupts

#12 View disk array levels

####################### how to find a performance bottleneck
The operating system completes a task with the system itself, the network topology, the routing device, the routing policy,
Access devices, physical wiring and other aspects of the closely related, when the problem of Linux, we should from
Application, operating system, server hardware, network environment comprehensive troubleshooting, positioning problems, and then solve.

<1> operating system current running state: System load, memory status, process state, CPU load,
<2> System Hardware Information: Disk IO, cup model, memory size, NIC bandwidth
<3> application-to-system resource usage (db/bug/memory overflow)
<4> interface program execution efficiency, slow query statements, SQL optimization, code execution efficiency is low.
For example, the problem:
Excessive use of CPU resources can cause a large number of waiting processes in the system, causing the application to respond slowly.
A large increase in the process can result in increased system memory resources
Physical memory is exhausted, the system uses virtual memory, and the use of virtual memory causes increased disk IO and increases
The overhead of the CPU.

The process of solving the problem follows:
View system system hardware, network devices, operating system configuration, application architecture, and program code

CPU bottlenecks: Application mail server, Dynamic Web server (CPU configuration and performance)
Scenario: Running the SMP kernel supports Hyper-threading, the higher the number of CPUs, the less hyper-threading performance increases,
CPU performance of two 4 cores is lower than the CPU performance of 8 single cores 25%-30%

Memory Bottleneck: Print server, database server, static Web server. (Increase memory size)
Scenario: 64-bit, open Linux large memory kernel support

Disk IO bottleneck: RAID0 (unsecured, at least 2 disks) RAID1 (Secure disk mirroring utilization 50%)
RAID5 (odd-even effect) RAID10 (at least 4 plates)
Scenario: Choose the right RAID level based on your business
RAID0: Applications with frequent read and write operations and low data security requirements
RAID1: No special requirements for reading and writing, applications with high data security requirements
RAID5: High read requirements, low write requirements, and ensure data security applications
RAID10: High demand for read and write, high data security requirements

System Performance Standard table:
Bad
CPU user%+sys%<70% user%+sys%=85% user%+sys%>=90%

Memory swap in (SI) =0 Per CPU with 0 page/s + swap in & swap out
Swap out (SO) =0

Disk iowait%<20% iowait%=35% iowait%>=50%

which
user% represents the percentage of time that the CPU is in user mode
sys% represents the percentage of time that the CPU is in system mode
iowait% indicates the percentage of CPU waiting for the input/output finish time
Swap in that SI represents the page import of virtual memory, swap from swap disk to ram
Swap out is a page export of virtual memory, from RAM swap to swap disk



################----------------------Performance analysis tools

#1 Vmstat
[Email protected] ~]# Vmstat 3 5
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 895504 12540 49092 0 0 3 3 1003 21 0 0 100 0 0
0 0 0 895504 12548 49084 0 0 0 19 978 21 0 1 99 0 0
0 0 0 895504 12548 49092 0 0 0 0 986 21 0 0 100 0 0
0 0 0 895504 12548 49092 0 0 0 0 969 20 0 0 100 0 0

Explain:
Si indicates that the disk is being transferred into memory
So means memory is being transferred to the disk
In general, SI and so values are 0, if not for a long time, indicates that the system memory is low, need to increase system memory.

BI represents read disk (KB/S)
Bo means write disk (kb/s)
Bi+bo reference value 100, if more than 1000, and a large WA value indicates a problem with disk IO. Consider disk read and write performance

In indicates the number of device interrupts per second observed at a certain time interval
CS indicates the number of context switches
The greater the in and CS values, the more CPU time is consumed by the kernel


The US column shows the percentage of CPU time consumed by the user process, and if it is longer than 50%, the optimizer or algorithm needs to be considered
The SY column shows the percentage of CPU time consumed by the kernel process, which indicates that the kernel consumes a lot of CPU resources when the SY value is high.
Us+sy reference value is 80%, if greater than 80%, indicates that there may be insufficient CPU resources

The ID column shows the percentage of time that the CPU is in idle state
The WA column shows the percentage of CPU time consumed by IO waits.
The higher the WA value, the more severe the I/O wait, based on experience, the WA reference value is 20%, exceeding the description I/O wait is critical.
The cause of I/O waits can be caused by a large number of random reads or writes to the disk, or by the disk controller's bandwidth bottleneck.


#2 SAR

#3 Iostat

#4 free-m (usage in m units)
[Email protected] ~]# free-m
Total used free shared buffers Cached
mem:1000 127 873 0 12 47
-/+ buffers/cache:66 934
swap:2047 0 2047

Empirical formula:
When the application is free of memory/system physical memory >70% indicates that the system memory resources are critically low and does not affect system performance.
When the application is free of memory/system physical memory <20% indicates that the system memory resource is tight and needs to increase system memory.
When the 20%< application available memory/system physical memory <70% indicates that the system memory resources basically meet the application needs, and temporarily do not
Affect system performance.
Uninterrupted detection of memory usage: free-b-S 5

#5 Uptime
[[email protected] ~]# uptime (1 minutes 5 minutes 15 minutes)
20:28:31 up 11:35, 1 user, Load average:0.00, 0.00, 0.00
3 value size can not be greater than the number of system CPUs, indicating high load, may affect system performance, occasionally greater than not worry,
If the value is less than the number of CPUs, it indicates that the CPU has idle time slices.

#6 netstat display native network links, run ports, routing table details

Netstat-a display all connections and listening ports on this machine
Netstat-n shows the active connections and ports that are currently established
Netstat-r Displaying routing table information
NETSTAT-T Show all TCP connections
Netstat-u display of all UTP connections
Netstat-i Display automatic Configuration Interface status

[Email protected] ~]# netstat-i
Kernel Interface Table
Iface MTU Met rx-ok rx-err rx-drp rx-ovr tx-ok tx-err tx-drp TX-OVR FLG
Eth0 0 3634 0 0 0 1950 0 0 0 Bmru
Lo 16436 0 172 0 0 0 172 0 0 0 LRU
Iface represents the interface name
MTU indicates the maximum Transmission Unit unit byte
RX-OK/TX-OK indicates how many packets have been received/sent accurately
Rx-err/tx-err indicates how many errors were generated when a packet was received/sent
RX-DRP/TX-DRP indicates how many packets were dropped when the packet was received/sent
RX-OVR/TX-OVR indicates how many packets have been lost due to errors
Normally the Rx-err/tx-err RX-DRP/TX-DRP RX-OVR/TX-OVR value should be 0
If not, the network quality must be a problem (Detect network card device)

#7 Top
top-22:36:51 up 13:43, 1 user, Load average:0.00, 0.00, 0.00
tasks:57 Total, 2 running, sleeping, 0 stopped, 0 zombie
Cpu (s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
mem:1024932k Total, 132320k used, 892612k free, 14056k buffers
swap:2096472k Total, 0k used, 2096472k free, 49868k cached

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND


3225 Root 0 12632 1112 876 R 0.3 0.1 0:00.05 Top


1 Root 0 10372 752 632 S 0.0 0.1 0:00.66 Init
#8 Nginx php-cgi

Open 10 Nginx process consumes 150MB of memory (15MB*10=150MB)
Open 64 php-cgi process consumes 120 of memory (20MB*64=1280MB)
In addition to the system itself consumes memory, the total consumption of less than 2G of memory.

If the server memory is small, you can only open 25 php-cgi processes so that consumes php-cgi consumption of total memory 500MB
Stress test with Webbench.
In the same hardware environment, Nginx's processing capacity is equivalent to 510 times times that of Apache.

This article is from the "Technical cock silk" blog, please make sure to keep this source http://yeqing.blog.51cto.com/3159086/1597040

Linux server performance Analysis and optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.