Evolution of High-concurrency Web Services-saving system memory and CPU

Source: Internet
Author: User

Evolution of High-concurrency Web Services-saving system memory and CPU
1. More and more concurrent connections

The number of concurrent connections faced by the current Web system has increased exponentially in recent years, and the high concurrency has become a norm, bringing great challenges to the Web system. The simplest and most crude solution is to increase Web system machines and upgrade hardware configurations. Although the current hardware is getting cheaper and cheaper, it is very costly to simply increase the number of machines to increase the concurrency. The combination of technical optimization solutions is a more effective solution.

Why is the number of concurrent connections increasing exponentially? In fact, from the perspective of the user base over the past few years, this number has not experienced exponential growth, so it is not the main reason. The main reason is that the web becomes more complex and the interaction is richer.

1. Increased page elements and complex interaction

More and more Web page elements are available. More resource elements mean more download requests. Web system interaction is becoming more and more complex, and the interaction scenarios and times are also greatly increased. Take the home page of "www.qq.com" as an example. If you refresh the page, there will be about 244 requests. In addition, after the page is opened, some scheduled queries or reported requests will continue to run.

 

Currently, in order to reduce repeated Connection creation and destruction, a persistent Connection (Connection keep-alive) is usually established for Http requests ). Once the connection is established, the connection will be retained for a period of time and reused by subsequent requests. However, it also brings about another new problem. Connection persistence will occupy resources on the Web server. If you do not fully use this connection, it will lead to a waste of resources. After a persistent connection is created, the first batch of resources are transferred and there is almost no data interaction afterwards. The system resources occupied by the persistent connection are automatically released until the timeout time is reached.

 

In addition, some Web requirements require long-term connection, such as Web socket.

2. The number of connections in mainstream browsers is increasing

In the face of more and more Web resources, the number of concurrent connections in mainstream browsers is also increasing. In the same domain, early browsers generally only have 1-2 download connections, while the current mainstream browsers usually have 2-6 connections. Increase the number of concurrent browser connections. In scenarios where many resources need to be downloaded, page loading can be accelerated. More connections are good for the browser to load page elements. When some connections encounter "network blocking", other normal download connections can continue to work.

This naturally increases the pressure on the backend of the Web system. More download connections occupy more Web server resources. During the peak hours of user access, self-built failover forms a "high concurrency" scenario. These connections and requests occupy a large amount of CPU, memory, and other resources on the server. It is necessary to use more download connections, especially for websites with more than 100 resources.

 

Ii. Web Front-end optimization to reduce server pressure

To relieve the "high concurrency" pressure, the frontend and backend must work together for optimization to achieve the maximum effect. The front-end of the user's first line of Web can reduce or reduce the effect of Http requests.

1. Reduce Web requests

The common implementation method is to control the static content through expire or max-age in the Http header and put the static content in the local cache of the browser. In the future, the Web server will not be requested, use local resources directly. The LocalStorage Technology in HTML5 is also used as a powerful local data cache.

 

After this scheme is cached, it does not send requests to the Web server at all, greatly reducing the load on the server and providing a good user experience. However, this scheme is ineffective for the first-time users and affects the real-time performance of some Web resources.

2. Reduce Web requests

The browser's local cache has an expiration time. Once it expires, you must request a new one from the server. At this time, there are two scenarios:

(1) If the server's resource content is not updated, the browser requests the Web resource and the server replies "you can continue using the local cache ". (Communication occurs, but the Web server only needs to make a simple "reply ")

(2) the file or content of the server has been updated, the browser requests Web resources, and the Web server transmits new resource content over the network. (In case of communication, the Web server needs to complete complex transmission work)

Here, the negotiation method is controlled through the Last-Modified or Etag of the Http protocol. At this time, the server is requested. if the content is Not changed, the server will return 304 Not Modified. In this way, you do not need to request the Web server to transmit the complete data file in a complicated way, as long as a simple http response can achieve the same effect.

 

Although the preceding request reduces the load on the Web server, the connection is still established and the request also occurs.

3. Merge page requests

For older Web developers, they should be more impressed before ajax prevails. Most of the pages are directly output, and there are not so many ajax requests. The Web backend completes the page content and returns it to the front-end. At that time, static pages were a wide range of optimization methods. Later, ajax, which is more interactive, gradually replaced, and more requests are sent to a page.

Because the mobile network (2G/3G) is much worse than PC Broadband, and some mobile phone configurations are relatively low, the loading speed will be much slower in the face of a Web page with more than 100 requests. Therefore, the optimization direction is re-returned to merge page elements to reduce the number of requests:

(1) Merge HTML to display the content. Embed CSS and JS directly into the HTML page and do not connect to the page.

(2) Ajax dynamic content merge request. For dynamic content, merge 10 Ajax requests into one batch information query.

(3) Merge small images. Use the CSS offset technology Sprites to merge many small images into one. This optimization method is also very common in PC-side Web optimization.

 

Merging requests reduces the number of data transmission times, that is, converting them from one request to one "batch" request. The above optimization methods achieve the goal of reducing the pressure on the Web server and reducing the connections to be established.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • 3
  • Next Page

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.