Two core architectural elements of a large web site (high-performance architecture for fine-grained web sites)

Source: Internet
Author: User
Tags mysql connection pool browser cache cpu usage website performance

I. High-performance indicators of the site from different perspectives, and its Optimization 1, the developer's perspective the developers focus on the performance of the application itself and its related subsystems, including response latency, system throughput, concurrency processing power, system stability and other technical indicators. The main ways to optimize site performance include using caching to speed up data reads, using clusters to increase throughput, using asynchronous messages to speed up request response and peaking, and using code optimization to improve website performance. 2, operation and maintenance personnel perspective operators pay more attention to infrastructure performance and resource utilization, such as network operator's broadband capabilities, server hardware configuration, data Center network architecture, server and network bandwidth resource utilization. The main optimization means are construction optimization backbone network, using cost-effective custom server, using virtualization technology to optimize resource utilization, performance test indicator 1, response time    open a website   a few seconds query a record in the database (indexed)   More than 10 MS Mechanical disk one-time address positioning  4 milliseconds read 1MB data from the mechanical disk sequence 2 milliseconds read 1MB data from SSD disk sequence  0.3 milliseconds read a data from a remote distributed cache Redis  0.5 milliseconds read 1MB data from memory More than 10 microseconds Java program Local method calls a few microseconds of network transmission 2KB data 1 microseconds 2, concurrent number noun interpretation, refers to the system can simultaneously process the number of requests, this number also reflects the load characteristics of the system. For a Web site, the number of concurrent users, which is the number of concurrent users who commit the request at the same time. Website system users number of online users "website concurrency number 3, throughput refers to the number of system processing requests per unit of time, reflecting the overall processing capacity of the system. For a website, you can use "Number of Requests/sec" or "page Count/second" to measure or use "visitors/days". TPS (number of transactions per second) is a common metric for throughput, plus HPS (number of HTTP requests per second), QPS (queries per second) 4, performance counters It is a data metric that describes the performance of a server or operating system. This includes metrics such as system Load, number of objects and threads, memory usage, CPU usage, disk and network IO. These indicators are also important parameters of the system monitoring, set the alarm threshold value, when the monitoring system found that performance counters exceed the threshold, the operation and the development of the alarm three, performance optimization 1, front-end performance optimization A, reduce the number of HTTP requests, image merge, js merge, CSS merge Ajax merge B, Using the browser cache is mainly caching some static resources CSS JS logo icons can be set by the HTTP Cache-control and expires properties, can set the browser cache, days or even months at some point, static file resource changes need to be timelyUse the client browser, which can be achieved by changing the file name. C, enable compression some text file compression rate of up to 80% enabling compression effectively reduces the amount of data transmitted by HTTP, reducing bandwidth and transmitting time. (Side effect is compression on the server's CPU pressure) d, CSS placed on the top of the page, JS placed on the page at the bottom of the browser will be downloaded after all the CSS page rendering, and JS just the opposite, the browser in the loading JS will immediately execute JS, there may be blocked the entire page, Cause the page to display slowly so JS best put the bottom, CSS put the page above E, reduce the cookie transmission on the one hand, the cookie is included in each request and response, too large cookie can seriously affect the data transfer. On the other hand, for some static resources such as css,script, sending cookies is meaningless, you can consider static resources to use independent domain name access, avoid requesting static resources when sending Cookie2, CDN Acceleration CDN Nature is still a cache, And the data is cached in the nearest place to the user, so that the user to the fastest speed to obtain data, that is, the so-called network access first jump because the CDN is not familiar in the network operator's room, these operators have terminal network service provider, so the first jump to the user request route to the CDN server, When the resource of the browser request exists in the CDN, it is returned to the browser directly from the CDN, the shortest path returns the response, speeds up the user access speed, and reduces the data center load pressure. This skill can greatly improve the page opening speed 3, reverse proxy traditional proxy server is located on one side of the browser, the proxy browser sends HTTP requests to the Internet, and the reverse proxy server is located on the side of the Web site, the proxy Web server receives an HTTP request, The request is then forwarded to the backend Web server, which is the equivalent of a network security barrier. In addition, you can save the hotspot cache content on the Web server, reducing the back-end pressure. At the same time, the reverse proxy can also achieve load balancing, improve the entire site high concurrency capability iv. Application Server performance optimization 1, distributed cache site performance optimization The first law: prioritize the basic principle of caching-optimized performance caching, which refers to storing data in relatively high-speed storage media for system processing. On the one hand cache access is fast, can reduce the time of data access, on the other hand, if the cached data is computed processing, then the cached data can be used directly without repeated calculations. The essence of the cache is a memory hash table, in the website application, the data cache is stored in the memory hash table in the form of a pair of key,value, and the time complexity of reading and writing the hash table data is O (1). The cache is mainly used to store data that reads and writes with very high and very little variation, such as the category information of the product, the search list information of the popular words, the popular commodity information and so on. 2, reasonable use of cache unreasonable use of cacheNot only can not improve the performance of the system will become a cumbersome, even risk. In practice, the situation of cache abuse is not uncommon, so bad oh A, frequently modified data, if the data stored in the cache, after the data is written to the cache, the application is too late to read the cache, the data has been invalidated, the system burden increases. In general, the data read and write more than 2:1, that is, write a cache, before the data update at least two times, the cache is meaningful. b, no hotspot access, the cache uses memory as storage, memory resources are valuable and limited, it is not possible to cache all the data, only the latest access to the data cache, and the historical data out of the cache. If the application system Access data does not follow the 28 law, that is, most of the data access is not concentrated on a small portion of the data, then the cache is meaningless, because most of the data has not been re-accessed by the extrusion cache C, data inconsistency and dirty read, usually set the cache data expiration time, Once the expiration time is exceeded, it should be reloaded from the database, so the application will tolerate a certain amount of time inconsistency, such as the seller has edited the product attributes, but it takes some time to be seen by the buyer D, cache availability, the cache is to improve the data read performance, The loss of cached data or the unavailability of the cache does not affect the processing of the application-it can fetch data directly from the database. But when the cache does not work, all the stress is concentrated in the database, and if the database is unable to withstand the sudden pressure, the whole system will collapse. With the master-slave cache, one is collapsed and the other is started, which solves the problem. But this design is against the original intention of the cache, the cache should not be used as a reliable data source to use, through the distributed cache, the data scattered across multiple servers, even if a cache server collapsed, but also only missing some of the data, restart, and then recover from the database E, cache warm-up, cache storage is the hotspot data, Hot data is the cache system using LRU (recently drunk unused algorithm) to the continuous access of data filtering out, F, cache penetration, if because of inappropriate business, or malicious attacks persistently high and concurrent requests for a non-existent data, because the cache does not save the data, all requests will fall on the database, can cause great pressure on the database, or even crash. A simple strategy is to cache non-existent data, set to NULLG, distributed cache architecture, distributed cache is not familiar to the crowd of multiple servers, to provide caching services in a clustered way, there are two ways of architecture, one is memcache as the representative of the non-communication distributed cache, Through a certain hash algorithm, to allocate a cache should be stored in the location, the server does not communicate, such a cache cluster can be easily expandable. H, multi-use asynchronous operations. Using the messaging team to make the call asynchronous can improve the extensibility of the site. such as log, do some calculations and other operations, put the background to do, first return the data to the user, this alsois to see business needs, there is a certain limit, not what business can do this I, using the cluster, memcache REDISJ, code optimization, resource reuse, thread pool (redis/mysql connection pool) k, storage performance optimization, namely: Hardware performance improvement, many, such as hard disk, mechanical hard disk- > SSD Some servers need a better CPU summary: Website performance optimization technology is a solution to the problem of website performance. While the site performance issues many things in the user high concurrent access to produce, so the site performance optimization of the main work when the high concurrent user access to improve the site response speed.

Two core architectural elements of a large web site (high-performance architecture for fine-grained web sites)

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.