First, the website performance test
(1) Performance Test indicators: ① response time, ② concurrency, ③ throughput, ④ performance counters;
(2) Performance test method: ① performance test; ② load test; ③ pressure test; ④ stability test;
(3) Performance optimization strategy:
① Performance Analysis: Check the log of the request processing each link, analyze which link response time is unreasonable, check the monitoring data analysis factors affecting performance;
② performance Optimization: Web front-end optimization, application server optimization, storage server optimization;
Second, the Web front-end performance optimization
(1) Browser access optimization:
① reduces HTTP requests: because HTTP is stateless, the cost of each request is expensive (need to establish a communication link, data transfer, and the server side for each HTTP request to start a separate thread to handle); The main way to reduce HTTP is to merge CSS, Merge js, merge picture (CSS Sprite, use offset to locate image);
② using the browser cache: Set the Cache-control and Expires properties in the HTTP header;
③ Enable compression: HTML, CSS, JS files can be enabled gzip compression, can achieve high compression efficiency, but compression will have a certain pressure on the server and browser;
④css put the top of the page, JS put the page at the bottom: the browser will not start to render the entire page after downloading the full CSS , so it is best to put the CSS on the top of the page, and the browser after loading JS will be executed immediately, it is possible to block the entire page, Cause the page to display slowly , so it is best to put JS at the bottom of the page;
⑤ reduce cookie transmission: On the one hand, too large a cookie can seriously affect data transmission, on the other hand, the access to some static resources (such as CSS, JS, etc.) is not meaningful to send cookies;
(2) CDN Acceleration:
The CDN (Content distribution network) is still a cache that caches data closest to the user , making it easy for users to get the data at the fastest speed. The so-called " network access first jump ", as shown in:
CDN Only caches high-frequency hot content (such as images, videos, CSS, JS scripts, etc.) , which can greatly speed up user access and reduce data center load.
(3) Reverse proxy:
The reverse proxy server is located in the website room, the proxy Web server receives an HTTP request and forwards the request as shown in:
The reverse proxy server has the following features:
① Protect website Security: Any request from the Internet must go through a proxy server first;
② accelerates Web requests by configuring caching: Reduces load pressure on real Web servers;
③ load balancing: Distribute requests evenly and balance the load pressure of each server in the cluster;
Third, Application server performance optimization
(1) Distributed cache:
PS: website Performance Optimization The first law: prioritize using caching to optimize performance . Caching refers to storing data in relatively high-speed storage media, such as memory, for quick processing by the system in response to user requests.
The ① cache is essentially a memory hash table in which the data is stored (key,value) in memory.
The ② cache is primarily used to store data that reads and writes very high and rarely changes , such as the product's category information, popular commodity information, and so on. In this way, when the application reads the data, it goes to the cache first, such as the cache is not or invalidated, and then fetched in the database, and re-written to the cache for the next visit. Therefore, it can improve the system performance, improve the data reading speed and reduce the storage access pressure .
③ Distributed Cache Architecture: On the one hand, the mutual communication Faction is represented by JBoss Cache, on the other hand, the non-communication faction is represented by memcached;
JBoss cache needs to synchronize the cache information to all machines in the cluster at a higher cost, while the memcached uses a centralized cache cluster management, caching and application separation deployment, the application through the consistent hash algorithm to select the cache server remote access to cache data, Cache servers do not communicate with each other, so the cluster size can be easily expanded, with good scalability.
Memcached consists of two core components: the service side (MS) and the client (MC), in a memcached query, the MC first calculates the key's hash value to determine the MS position of the kv pair. When MS is determined, the client sends a query request to the corresponding MS, allowing it to find the exact data. Because there is no interaction and multicast protocol, the impact of memcached interaction on the network is minimized.
(2) Asynchronous operation:
① uses Message Queuing to make calls asynchronous, improving Web site extensibility, and improving website performance;
② Message Queuing has the effect of clipping , the transaction messages generated by the short-time high concurrency are stored in the message queue, thus flattened the peak concurrent transaction;
PS: anything that can be done later should be done later . The premise is: This thing can be done later.
(3) using the cluster:
① in high concurrency scenarios, a server cluster of multiple servers is built using load Balancing technology for one application.
② can avoid the slow response of a single server due to heavy load pressure, which makes the user request have better response delay characteristics ;
③ load Balancing can be either hardware-based or software-loaded. Commercial hardware load devices (such as well-known F5) costs are usually high (a hundreds of thousands of million is normal), so if conditions allow us to adopt soft load, soft load solution of two core issues is: Choose who, forwarding, the most famous is the LVS(Linux Virtual Server).
PS: LVS is a four-layer load balancer, that is, based on the fourth layer of the OSI model-the transport layer, where our familiar Tcp/udp,lvs support tcp/udp load balancing.
The retransmission of LVS is implemented mainly by modifying the IP address (NAT mode, which is divided into the source address to modify the Snat and the target address to modify the Dnat) and the target Mac (Dr Mode). For more information about LVS, please refer to: http://www.importnew.com/11229.html
(4) Code optimization:
① Multithreading: The Reasons for using multithreading: One is IO blocking, and the other is multi-CPU, is to maximize the use of CPU resources, improve system throughput capacity, improve system performance;
② Resource reuse: The goal is to reduce the creation and destruction of costly system resources , mainly in two modes: Singleton (Singleton) and object pool. For example, in. NET development, frequently used thread pools, database connection pools, etc., are essentially object pools.
③ data structure: it can greatly optimize the performance of the program in different situations to reasonably use the appropriate structures.
④ Garbage Collection: Understanding the garbage collection mechanism facilitates program optimization and parameter tuning, as well as writing code for memory security. This is primarily for Java (JVM) and C # (CLR)-type languages that have a GC (garbage collection mechanism).
Four, storage performance optimization
(1) Mechanical hard drive or solid state drive?
① mechanical HDD: Drive the head arm through the motor, drive the head to the specified disk location to access the data . It enables fast sequential read and write, slow random read and write .
② Solid State Drive (also known as SSD): no mechanical device, data stored on a long-lasting memory of the silicon Crystal , so can be as fast as memory random access .
In the current website application, most of the application access data is random, in this case the SSD has better performance, but the cost-effective needs to be improved (pretty expensive, click).
(2) B + Tree vs LSM Tree
① traditional relational database is widely used B + tree, B + Tree is the data after the sequence of storage, speed up data retrieval speed.
PS: Most DB currently uses a B + tree with a Level two index, with a tree hierarchy of up to three layers. Therefore, it may take 5 disk accesses to update a record (three disk accesses get data index and row ID, one data file read operation, one data file write operation, and finally know how much trouble the database operation is time consuming)
②nosql (for example, HBase) products are widely used in LSM trees:
The idea is to keep the modified increments of data in memory and to write them to disk in bulk after the specified size limit is reached . However, when reading a bit of trouble, you need to merge the history of the disk and the most recent changes in memory, so write performance greatly improved, read may need to see whether the memory hit, or need to access more disk files.
the principle of the LSM tree is to split a tree into N small trees, which are first written into memory, and as the small trees grow larger and smaller trees are purged and written to disk, the trees on the disk can be merged and merged into a tree to optimize read performance.
The advantage of the LSM tree is that a data update on the LSM tree does not require disk access, and can be done in memory, much faster than a B + tree.
Reference documents
(1) Hae, "large Web site technology architecture-core principles and case studies", http://item.jd.com/11322972.html
(2) Zhou Yan, "memcached detailed", http://blog.csdn.net/zlb824/article/details/7466943
(3) Baidu Encyclopedia, cdn,http://baike.baidu.com/view/8689800.htm
(4) Wang Chen Pure, "Web infrastructure: Load balancing and LVs", http://www.importnew.com/11229.html
(5) Hui Guang, "B-tree, B-tree, + + Tree", http://www.cnblogs.com/oldhorse/archive/2009/11/16/1604009.html
(6) Yanghuahui's blog, the origin of LSM, design ideas, and the index applied to HBase, http://www.cnblogs.com/yanghuahui/p/3483754.html
The high-performance architecture and optimization of the website technology architecture of Large website