Basic concepts
- Bandwidth: Generally speaking bandwidth, such as 8M bandwidth, refers to the speed of data transfer between the host and the internet operator's switch, because the traffic on the data link layer is implemented by the control receiver. and the Gigabit network card refers to the transmission speed of the network card is 100mbit/s, refers to the speed of the network card to send data
- Throughput Rate: Unit is REQS/S, refers to the server's concurrency capacity, is the number of requests processed by the server per unit of time. The maximum throughput is the maximum number of requests that the server can handle per unit of time. The stress test method is usually used to simulate a sufficient number of concurrent users to continue sending A certain HTTP request, and statistics the total duration of the test, calculated based on the throughput rate under this pressure, is an average calculated value. Note the continuous sending of requests by each user mentioned in the stress test means that the next request is sent after sending a request and receiving the corresponding data. So 1 users continuously send 1000 requests to the server and 100 users to the server continuously send 10 requests to the server caused by the pressure is not the same , the latter causes more pressure because the network card receives more requests for the buffer queue at the same time.
- The throughput rate is based on the premise that pressure and the nature of the requested resource, the pressure typically consists of two parts, the number of concurrent users and the total number of requests, That is, simulating how many requests the user sends to the server at the same time. The nature of the request resource is the description of the resource represented by the requested URL, such as a 1kb static file or dynamic content containing 19 database queries. So the prerequisites for throughput include:
- Concurrent users: the number of users who are sending requests to the server at a time
- The maximum number of concurrent users that the server supports, that is, the max number of concurrent users is a certain premise, That is, to meet the server and user expectations of the greatest benefits, the loss of the premise of the maximum concurrency will be greater, but the user experience will be bad, such as waiting too long, the server throughput rate will be very low
-
- Total requests
- Request Resource Description
- Long connection: In itself is a common way of TCP communication, that is, in a TCP connection to continuously send multi-point data and continuously open the connection. The corresponding is a short connection, that is, after the connection is established, send a copy of the data will be disconnected, and then establish a connection to send the next data, the cycle. HTTP long connections require the browser and server to work together, while the browser needs to maintain a TCP connection and reuse, on the other hand, the server can not prematurely shut down the connection. Currently, browsers support long connections, which represent long-connected declarations in the HTTP request data headers that are emitted: Connection : Keep-alive. For the effective use of long connections, the key point is the long connection timeout setting, that is, when the long connection is closed, this setting appears both on the browser and the Web server, because both parties can actively close the connection. The default timeout for IE7 is 1 minutes, The Web server provides time-out settings in the configuration file. When the browser and server timeout settings are inconsistent, whichever is the shortest time-out
Cache
-
-
-
- Determines whether the current time cache file expires based on the expiration time of the cache file
- cache files can also be placed in memory (memcached) In addition to the disk, or in separate cache servers. With memcached, you can easily save the cache to a different server
- The cache validity period is a value that needs to be considered, and the expiration date is too large to increase the cache hit rate. However, the content of dynamic Web pages is not updated in time, and the validity period is too small to create cache frequently. In addition to constantly adjusting the cache validity period, the caching mechanism provides an effective cache control path that can force all caches to be emptied at any time
-
- Regenerate static content when data is updated
-
Browser Cache
- As much as possible, the content of the Web site is cached in the user's browser, which reduces the browser's computational overhead to some extent. Browsers typically create a directory in the user's file system to hold the cache files and make the necessary tokens for each cache file, such as the Expiration Time
- The process of caching negotiation: when the browser requests content from the Web server, the Web server tells the browser what content can be cached, and when the browser caches the content, it asks the server if it can use the local cache, and the server responds with the query. Whether to allow the browser to use local cache or to send the latest content back to the browser
- There are two ways to negotiate:
- last-modified: The dynamic program can add the last modification time to the HTTP response header returned to the browser, which is GMT time. The browser will add if-modified-since to the HTTP request when the same content is requested again: time, This indicates whether the content requested by the server is updated after this time. For static content The Web server does its own checking of whether the browser cache is out of date, and if it is dynamic, it needs to be checked by the dynamic program itself. If the content is not updated, the HTTP corresponding header returned to the browser contains 304 not modified information, indicating that the Web server tells the browser that the content is not updated, that the browser can use locally cached content, and that the server does not pass the content body to the browser
- etag negotiation, the ETag is a string of encodings, and the Web server can freely define the format and implementation of the etag, such as the MD5 value of the file content as the ETag. The corresponding header returned by the Web server will contain the ETag value, and the Web browser will add the If-none-match:etag value to the request header if it asks whether the change has changed.
- Browser cache expiration Date: Use the expires tag to tell the browser when the cache expires, suggesting that the browser can use the cache directly before the cache expires, without asking the server, which can save bandwidth and server processing overhead. For static content Web servers, the expires tag is not turned on by default, and for dynamic content the expires tag still needs to be added by the program itself, similar to the previous last-modified. Note that expires is the server's time, If the user's local time is inconsistent with the server time, the validity check of the local cache may be affected. The HTTP protocol also has a Cache-control tag that can compensate for the expires, the format is Cache-control:max-age=<second>, and it indicates the relative time of the cache expiration, in seconds, and is relative to the browser's local time. The browser takes precedence over the value of Cache-control when the HTTP response header contains both expires and Cache-control
- How to request a page:
-
- Ctrl+f5: Force refresh, do not apply cache negotiation, get the latest version of all content
- F5: Allows the browser to attach the necessary cache negotiation in the request, but does not allow the browser to use the local cache directly, that is, to let the last-modified play a role, but invalid for expires
- Go To button: The browser will use the local cache for all content that does not expire, and the expires tag only works in this way
Web server Caching
。。。。。。。。。。
Reading notes-building a high-performance Web site