Analyzing website performance optimization point from the process

Source: Internet
Author: User
Tags prefetch website server domain name server browser cache domain server website performance

1 starting from an old question

A user from the input URL to press ENTER to see the page. What happened in the middle?

The browser initiates the DNS resolution process and obtains the ip--browser to transmit the request to the server--the server accepts and processes the request--server transfer response to the user's browser--the browser calculates rendering to the user based on response.

2 minutes, three stages.

We divide the whole process of chapter one into three segments:

1, the first paragraph in the user and browser side, is mainly responsible for issuing user requests, and receiving response data for calculation rendering display to the user;

2, the second paragraph on the network, is responsible for the request data, the response data transmission;

3, the third paragraph in the website server side, is responsible for the request data processing (executes the program, accesses the database, the file and so on), and returns the result;

2.1 First Path 2.1.1 DNS cache

Now the main browser defaults to the DNS prefetch feature (DNS Prefetch), of course, you can also proactively tell the browser my site needs to do DNS prefetching:

<meta http-equiv= "X-dns-prefetch-control" content= "on"/>

2.1.2 Optimization from the rendering process

The process by which the browser evaluates the data for rendering:

1, browser parsing response data;

2, the browser to create a DOM tree;

3, the browser download CSS style, and apply to the DOM tree, to render;

4, the browser download JS file, start parsing execution;

5, display to the user.

From this process, we can find a lot of places that can be optimized. First, we can try to control the page size, so that the browser parsing time is shorter, and the multiple CSS files, JS file file merge compression reduce the number and size of file download, also note that the CSS in front of the page, JS access to the page, so that the page can be rendered first, and then execute the JS script, A better experience for the user. Finally, I can set up the browser cache and read the content from the cache on the next visit, reducing the HTTP request.

<meta http-equiv= "Cache-control" content= "max-age=5"/>

This code illustrates that the browser is enabled for caching and does not access the server again for 5 seconds. Note that the settings for the cache need to be configured appropriately with your business features.

2.2 Second Path

The second path on the network, the time spent also includes the transmission time of the request data and the transmission time of the response data, this two time depends on the speed of data transmission, here we will say a noun "bandwidth". Bandwidth 20M, what does that mean? We know that the bandwidth speed is divided into upstream and downstream speed, that is, upload and download speed. Bandwidth 20M for the user is the download speed of 20M (20x1024x1024 bit rate), converted into byte 20m/8=2.5m. That is to say, 20M bandwidth download speed theory can reach 2.5m/s.

The whole process is from the way of transmission: The user sends the request data (upload), the Web server accepts the request data (download), the Web server returns the response data (upload), the user accepts the response data (download).

Let's go further into the second path:

Represents the general situation of the network when the user accesses the Web server, it can be seen from the diagram that assuming that the Web server from the telecommunications network access, and user A as a telecommunications broadband users, you can quickly access the backbone of the telecommunications network to the Web server. User B, user C as mobile and unicom users need to pass through the operator's interconnection through a longer path to access to the server.

For this scenario, we can use the following methods to optimize:

1, in the developed regions of the operators IDC (Internet Data Center, can be understood as a computer room) to deploy the Web server, the user of each operator can access the server through their own backbone network.

2, the purchase of agent services, that is, the original Unicom users need to pass through the backbone of Unicom--unicom interconnection routers---telecom backbone---Web site server process. Through the proxy service, the proxy server connects directly to the telecom backbone and accesses the website server.

3, in the major regions of the city to purchase CDN services, cache the corresponding data, users can first obtain the request data from the nearest CDN operator.

2.3 Third Path

The third path is the process of internal processing of the Web server, including the execution of programs, access to files, databases and other resources.

This is the best place for us to play:

1, using the cache, depending on the need to use local cache or distributed cache;

2, using asynchronous operation, this way can not only improve performance, but also improve the scalability of the system;

3, code optimization;

4. Storage optimization

Large-scale web site in the vast amount of data read and write to the disk caused great pressure, the system's biggest bottleneck is the disk read and write. Consider using disk arrays, distributed storage to improve storage performance.

3 Performance indicators and testing

The above through the analysis of user access to the site process to consider how to improve user-perceived performance, for the user to say performance is fast and slow. But for us, it can't be described in such a nutshell, we need to quantify him and measure it with some data metrics. Here are a few nouns: response time, concurrency, throughput.

Response time: Is the time when the user makes a request to receive the response data;

Concurrency: How many user requests can be processed by the system at the same time;

Throughput: The number of requests processed by the system within a unit of time;

In order to understand these three concepts in a popular way, we take the toll station of Expressway as an example: response time refers to the time when a car passes through a toll station, that is, the time when a vehicle enters a toll station, pays, gates, and leaves a toll station. Concurrency is the number of vehicles that can be accessed at the same time, which is understood as Throughput is the number of cars that the toll station leads to over a period of time.

Attachment 1: By the way, the DNS parsing process

Reference http://369369.blog.51cto.com/319630/812889/

0, enter the www.qq.com domain name in the browser, the browser first query its own DNS cache, the time is the browser itself, some browsers can modify this time, like Firefox default definition cache for 60 seconds. If there is no record of this domain name in the browser cache, the operating system API query is invoked.

1, the operating system will first check their local hosts file whether there is this URL mapping relationship, if there is, first call this IP address mapping, complete the domain name resolution.

2, if the hosts do not have this domain name mapping, then find the local DNS resolver cache, whether there is this URL mapping relationship, if there is, direct return, complete the domain name resolution.

3, if the hosts and the local DNS resolver cache does not have the corresponding URL mapping relationship, first will find the TCP/IP parameters set in the preferred DNS server, where we call it a local DNS server, when the server receives the query, if the domain name to query, included in the Local Configuration zone resources, The parsing result is returned to the client and the domain name resolution is completed, which is authoritative.

4, if the domain name to be queried is not resolved by the local DNS server zone, but the server has cached this URL mapping relationship, call this IP address mapping, complete the domain name resolution, this resolution is not authoritative.

5, if the local DNS server local zone file and cache resolution are invalidated, according to the local DNS server settings (whether set forwarders) to query, if not in the forwarding mode, local DNS will send the request to 13 root DNS, the root DNS server receives the request will determine the domain name (. com) Who is authorized to administer and returns an IP that is responsible for the top-level domain name server. After the local DNS server receives the IP information, it will contact the server responsible for the. com domain. After the server that is responsible for the. com domain receives the request, if it cannot resolve itself, it will find a management. com domain's next-level DNS server address (qq.com) to the local DNS server. When the local DNS server receives this address, it will find the qq.com domain server, repeat the above action, query until the www.qq.com host is found.

6, if the use of a forwarding mode, this DNS server will forward the request to the first level of DNS server, from the previous level of the server to resolve, the previous level of the server if it can not resolve, or find root DNS or transfer requests to the upper ancestor, in this cycle. Whether the local DNS server uses either forwarding or root hints, the result is returned to the local DNS server, which is then returned to the client.

From the client to the local DNS server is a recursive query, and the DNS server is an interactive query between the iterative query.

Attached 2: References to Blogs

Http://www.cnblogs.com/leefreeman/p/3998757.html

http://369369.blog.51cto.com/319630/812889/

Analyzing website performance optimization point from the process

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.