"Technical Architecture of Large Websites" Reading Notes--High-performance Architecture of Websites

      Enterprise-level application projects generally need to undergo strict third-party performance testing before going online to the production environment. What are the indicators of performance testing? How to design a high-performance architecture? Below I combine the description in the book and my own project experience. According to these two questions, I will explain in two parts. The first part is the website performance test indicators, and the second part is the performance optimization method.

Website Performance Test Metrics

  1. Maximum number of concurrent users. The maximum number of concurrent users can directly reflect the concurrent processing capability of the system and is determined by the actual number of users.
  2. business response time. The business response time is an indicator tested under the condition of the maximum number of concurrent users of the system. There are four common scenarios: system login, opening documents, querying reports, and adding documents. Generally, it is required to be within 3 seconds.
  3. business throughput. Refers to the number of requests processed by the system per unit of time, reflecting the overall processing capability of the system, and is also an indicator tested under the maximum number of concurrency, generally measured by the number of requests per second.
  4. System resource performance. Common indicators are CPU utilization and memory occupancy, which are important parameters for system monitoring. Generally, CPU utilization is required to be less than 40% and memory occupancy is less than 80%.

performance optimization methods

    1. Front-end performance optimization

    General front-end performance optimization focuses on speeding up page loading. Common methods are as follows:

  •     Reduce http requests. It can be solved by combining css, js and images.
  •     Use browser cache. It is recommended to use the requireJs framework. The framework uses an amd configuration file to define the path of each front-end component. After the system is started, the browser caches all the plug-ins after accessing the page for the first time. Get resources from the server side.
  •     Enable compression. Compress some front-end plug-ins and files with a large amount of js code.
  •     JS is placed at the bottom. This is determined by the rendering mechanism of the browser. When the browser downloads the js from the server, the js will be executed immediately. Therefore, in order to avoid the loading delay of the page, place the js at the bottom of the body tag.
  •     CDN acceleration. By adding a CDN server to cache various static resources, such as pictures, files, scripts, static web pages, etc. When these static files are accessed frequently, caching them to CDN can greatly improve the opening speed of web pages.
  •     reverse proxy. By adding a reverse proxy server, the static content accessed by users can be cached. When other users access it, they can be returned directly from the proxy server without sending a request to the application server.

    2. Server performance optimization

    The server is the core and most complex part of an application system. Common optimization methods are as follows:

  •     cache. The first law of network performance optimization: Prioritize the use of cache to optimize performance. On the one hand, the cache can speed up the access speed. On the other hand, if the cached data is obtained by calculation, the cache also plays a role in reducing the calculation time.
    • Fundamentals of caching. The storage medium of the cache is generally the memory and the hard disk. The essence of the cache is an in-memory hash table, and the data cache is stored in the in-memory hash table in the form of a pair of key-values. The cache is mainly used to store data with a high read-write ratio and little change. I have tried the application system after high concurrent login, and the login becomes slower and slower. Later, I found out that the reason is because the home page executes more queries after login, which leads to the gradual increase of server load pressure. For the menus and charts on the home page Statistically summarized data, because it will be read frequently and rarely modified, it is suitable to use cache here.
    • Use cache wisely. It is not suitable to use the cache for frequently modified data. At the same time, pay attention to the update of the cached data. You can update the cache immediately when the data is updated to avoid the dirty read of the cache.
  •     Asynchronous operation. Anything that can be done later should be done later. Taking a new document as an example, when the new button is triggered, the server needs to save the form data, and after saving, it needs to start the business process and send a notification email. If you wait until all the steps are completed before returning to the front end, it will take a lot of time. In fact, you only need to know that the document is saved successfully, and you can check it later when the process starts. At this time, asynchronous processing can be used to put the startup process and sending mail operations into the thread (message queue) for processing. It also improves the system throughput. If the message queue can also effectively control the excessive concurrency, when the message queue length exceeds the maximum number, the user request will be directly discarded and an error will be returned.
  •     Use clusters. In high concurrency scenarios, build an application server cluster and add a load balancing server to avoid the problem of slow response of a single server due to excessive load pressure.
  •     Code optimization. Reasonable optimization of business code can greatly improve website performance. The specific best practices will not be discussed here, and will be described in detail in separate chapters later.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325606839&siteId=291194637