Web applications, essentially a variety of Web content from the Web site to reach the browser, presented to the user. The less time the user wants to get the Web content, the better. From the point of view of Web site, it is necessary to solve the time delay problem of concurrent access for a large number of users, which manifests as two metrics: throughput and concurrency. Throughput refers to the number of requests completed (REQ/S) within the unit time. Concurrency refers to the number of clients that simultaneously initiate the request (the browser sends a request with a certain degree of concurrency, such as sending 4 requests at a time, 4 clients here). In a certain degree of concurrency, the greater the throughput, the lower the customer's sense of delay, the higher the performance of the site.
The throughput of a Web site is not a constant under different concurrency degrees. Generally speaking, when the concurrency is less than a threshold, the site can maintain a relatively stable throughput, and over this threshold, the site's throughput is rapidly declining. This threshold is determined by the message processing speed of the Web site. Assuming that network bandwidth is not a bottleneck, the request message reaches the site and is cached in the kernel's buffer queue, which is then processed in parallel. When the Web site processing messages faster than the speed of the message buffer, queues in the message will accumulate a lot, resulting in rapid processing delay, the throughput of rapid decline. In the usual stress test model, it is generally simulated that multiple users send messages in parallel, and a user receives a response from the previous message before sending the next message. So if the website message processing time extension, the message sends the interval naturally to lengthen, in the unit time the message which surges to the website reduces, this can cause the website throughput to descend, thus has reached the message processing and the message arrival balance under a new throughput. But in the real scene, in the peak of the visit, the impatient user will constantly refresh the browser, surging to the site of the request message volume continues to exceed the actual processing capacity of the site, the request was piled up in the site's buffer, until the site's memory exhaustion, resulting in the site paralysis. Therefore, in the real scene to avoid the site paralysis, to take the flow control measures.
To speed up Web sites and improve Web performance, the following measures are generally available:
Improved server IO concurrency model. There are three kinds of classic IO concurrency models: process concurrency, thread concurrency, and event concurrency. In these three models, event concurrency is the most lightweight because multiple events are handled in a single thread, significantly reducing thread switching time, and saving memory. Therefore, the NGINX/LIGHTTPD with the event concurrency model can withstand the highest degree of concurrency. Caching Web site content. There are two cases: 1 cache dynamic content of static results, accelerate dynamic content, 2 in close proximity to customers to cache the content of the site, save bandwidth. Accelerates dynamic content computing. For CPU-intensive dynamic scripts, cache opcode, and do not parse the original script every time. The server script parser runs a cache of opcode, which is much more efficient than parsing the original script directly. This is why the Php/python parsing engine needs to compile the original script into opcode, and then through the virtual machine to resolve the cause of the execution, so that it can achieve the same performance as Java, C #. More transformations, the root cause is to improve performance. Accelerates database access. There are several means: 1 increase distributed caching, cache query results, 2 index, 3 increase DBMS internal query cache, 4 DBMS cache index and data. The latter two items are available through the database configuration. Increase network bandwidth. If network bandwidth becomes a bottleneck, increase network bandwidth appropriately.
The logical schema is shown in the following illustration.
Different web content, because of different features, performance bottlenecks are often different, the required web acceleration strategy is not the same.
Static content (small file). For example, a variety of picture content, the required bandwidth is relatively small. Web site processing bottlenecks in IO concurrency. Therefore, you can choose a lightweight Web server that supports the event concurrency model, such as NGINX/LIGHTTPD. Meanwhile, in order to avoid frequent TCP establishment and connection, the KeepAlive long connection function of HTTP protocol can be opened. This allows for a large number of idle connections that require the epoll concurrency model to be turned on. At the same time, the update is not frequent content, the HTTP protocol can be used to Last-modified/if-modified-since,etag/if-none-match,expires/cache-control and other header domain negotiation, in the browser cache contents. Static content (large file). For example, a variety of download resources, the need for large bandwidth. At this time the bottleneck is often in bandwidth, the cache server can be deployed near the client's domain, and the caching policy of the cache server also adheres to the HTTP header domain negotiation. Static content (VIDEO). Video content is often very large, but users do not pursue the highest download speed, as long as can catch the speed on the line. But the video lasts a long time, a statistically significant bandwidth requirement, and today's high-definition video, one-way video, has a high bandwidth requirements. So the caching servers that are deployed nearby are often the choice. Dynamic content. Bottlenecks in dynamic computing and databases, generally implementing the following strategies: 1 cache opcode;2) Accelerated database access, 3 to update dynamic content infrequently, using cache server or Web browser cache static content. Dynamic content after static often shows amazing concurrency performance improvement effect.
Fully consider the content characteristics of the site, flexible application of the above acceleration strategy, can reduce the server/bandwidth costs, obtain the highest cost-effective.