HTTP Performance Optimization

FIG above, the performance can be optimized HTTP from three aspects.

1. Server

Measure server performance, mainly in the following:

a. Throughput (or TPS, RPS, QPS)

b. Concurrent

c. Response time

d. Resource utilization (CPU, memory, disk, network)

-> increase throughput, higher throughput, the better the performance of the server!

-> increase the number of concurrent, the greater the number of concurrent support, the better the performance of the server!

-> reduce the response time, the shorter the response time, the better the performance of the server!

-> rational use of server resources, is certainly not too high, too low, there may be problems!

-> Linux server monitoring tools are top, sar, glances, etc.

2. Client

Because the data to be retrieved from the server through the network, so it is the most basic performance metrics: delay.

The so-called "delayed" is actually "wait" and wait for the client when the end time data takes to arrive.

The reason for the delay, there are a few:

a. Distance: delay caused due to the geographical distance, is not customer service, such as access to the site thousands of kilometers away.

b. bandwidth

c. DNS queries (if the domain name is not in the local cache, then)

d. TCP handshake (must go through SYN, SYN / ACK, in order to establish the connection after three ACK packet)

-> HTTP for performance optimization, there is a dedicated test site: WebPageTest, or use the browser's developer tools

-> a HTTP "request - response" during the delay time is very large, there is likely to account for more than 90%

-> So, the key to the client optimized to reduce delays

3. The transmission link (transmission link between the client and server)

CDN using other techniques, in short, to increase bandwidth and reduce latency, to optimize the transmission speed.


----------------------------------------------- specific optimization means------------------------------------------------- ---------

The main is to optimize the performance of the server.

1. Front: PageSpeed ​​other tools can be used to detect and optimize the prompts.

2. Rear: mainly the following aspects

a. hardware, software or services

For example, replace the powerful CPU, memory, disk, bandwidth, such as using CDN

b. Servers selection, tuning parameters

Use high-performance servers, such as Nginx, its powerful ability to achieve reverse proxy "static and dynamic separation", Tomcat and other dynamic pages to static resources to Nginx

Further, Nginx can tune itself has parameters, such as load balancing is disabled lock, increase the connection pool, such as a CPU binding

For more HTTP protocol must enable long connections, TCP and SSL because the cost of establishing a new connection is very high, the client may account for half of the total delay

New features of TCP "TCP Fast Open", similar to the TLS of "False Start", the initial handshake can transmit data when it is possible to open this feature in the operating system and Nginx, the reduction in the net external network and handshake delay .


Use the built-in HTTP protocol "Data Compression" coding, you can choose a standard gzip, you can also try a new compression algorithm br

However, data compression should be noted that when selecting the appropriate compression ratio, the more powerful the better compression than

c. Cache

Internal website system, you can use Memcache, Redis cache and other specialized services, the intermediate results and resource calculation stored in memory or hard disk

Web server first checks the cache system, if there is data immediately returned to the client

In addition, CDN network acceleration feature is built on top of the cache, so to speak, if no cache, there is no CDN.

Make good use of caching feature key is to understand how it works, as resources are added each ETag and Last-modified field, then Cache-Control, Expires set cache control attributes.

The most basic is the max-age period, marking resources cacheable time. For static resource image, CSS, etc. You can set a longer period of time, such as one day or

A month later, the dynamic resources, unless it is very high in real time, you can also set a shorter period of time, such as one second or five seconds. Once such resources reach the client, on

Are cached in the life of the server will not send the request again.


Guess you like

Origin blog.51cto.com/11009785/2449286