In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this article, the editor introduces in detail "what is the high-performance system architecture design method behind a large website". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "what is the high-performance system architecture design method behind large-scale websites" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.
1. Performance test 1.1. Performance index
The main indicators of website performance testing are:
Response time-response time (RT) refers to the time from the time the client sends a request to the end when the client receives the response result returned from the server. The response time consists of three parts: the request sending time, the network transmission time and the server processing time.
Concurrency-number of requests and transactions processed by the system at the same time.
Throughput-TPS (transactions per second), HPS (HTTP requests per second), QPS (queries per second).
Performance counters-system load, number of objects and threads, memory usage, CPU usage, disk and network IO, etc. These indicators are also important parameters for system monitoring.
1.2. Performance test method
Performance testing
Load testing
Pressure testing
Stability test
1.3. Performance test report
Example of performance test report:
1.4. Performance optimization strategy
Performance analysis-if the request response is slow, there is a performance problem. Each link of the request needs to be analyzed one by one to find out where performance bottlenecks may occur and locate the problems. Check the monitoring data and analyze the main factors affecting performance: memory, disk, network, CPU. It may be that the code or architecture is not designed properly, or the system resources are indeed insufficient.
Performance optimization-according to the hierarchical architecture of the website, performance optimization can be divided into front-end performance optimization, application service performance optimization and storage service performance optimization.
two。 Front-end performance optimization 2.1. Browser access optimization
Reduce HTTP requests-HTTP requests require the establishment of communication links and data transmission, which is expensive, so reducing the number of HTTP requests can effectively improve access performance. The main means to reduce HTTP is to merge Css, JavaScript and pictures.
Use browser caching-because static resource files are not updated frequently, they can be cached in the browser to improve performance. You can set the browser cache by setting the Cache-Control and Expires properties in the HTTP header.
Enable compression-compress static resource files on the server side and decompress them on the browser side, which can effectively reduce the amount of data transferred. Since the compression ratio of text files can reach more than 80%, static resources such as Html, Css, and JavaScrip can be compressed.
CSS on the top of the page, JavaScript on the bottom of the page-the browser will download all the Css before rendering the entire page, so the best way is to put Css on the top of the page, let the browser download Css;JavaScript as soon as possible, on the contrary, the browser loads JavaScript and executes immediately, which may block the whole page and cause the page to display slowly, so JavaScript had better be placed at the bottom of the page.
Reduce Cookie transfer-Cookie is included in every request and response of HTTP, and too large Cookie will seriously affect data transmission.
2.2. CDN
CDN generally caches static resources.
The essence of CDN is still a cache, and the data is cached in the place closest to the user, so that the user can get the data as quickly as possible, that is, the so-called first hop of network access.
2.3. Reverse proxy
The traditional proxy server is located on the side of the browser, the proxy browser sends HTTP requests to the Internet, while the reverse proxy server is located on the side of the website computer room, and the proxy website server receives HTTP requests.
The reverse proxy server can configure the caching function to accelerate Web requests. When the user accesses the static content for the first time, the static content will be cached on the reverse proxy server.
Reverse proxy can also achieve load balancing, and the cluster built by load balancing can improve the overall processing capacity of the system.
Because all requests must first go through the reverse proxy server, some attacks on IP can be shielded to protect the security of the website.
3. Application service performance optimization 3.1. Distributed cache
The first law of website performance optimization: give priority to the use of caching to optimize performance.
Caching principle
Caching refers to storing data in a storage medium with relatively high access speed for processing by the system. On the one hand, the cache access speed is fast, which can reduce the data access time; on the other hand, if the cached data is processed by calculation, then the cached data can be used directly without repeated calculation, so the cache also plays a role in reducing the computing time.
The essence of caching is an in-memory HASH table.
Cache is mainly used to store data with high read-to-write ratio and little change, such as category information of goods, search list information of popular words, information of popular goods and so on.
Rational use of cach
Choice of cached data:
Do not store frequently modified data
Do not store non-hot data
Data inconsistency and dirty reading:
The cache has a validity period, so there are data inconsistencies and dirty reading problems for a certain period of time. If you cannot accept it, you can consider updating the cache policy immediately with data update
Cache issues need to be considered: cache avalanche, cache penetration, cache warm-up
3.2. Asynchronous operation
Asynchronous processing is generally done through distributed message queues.
Asynchronous processing can solve the problem:
Asynchronous processing
Application decoupling
Flow cutting edge
Log processing
Message communication
3.3. Using clusters
In high concurrency scenarios, load balancing technology is used to build a server cluster composed of multiple servers for an application, and concurrent access requests are distributed to multiple servers for processing, so as to avoid the slow response of a single server due to heavy load, so that the user request has a better response delay.
3.4. Code optimization multithreading
From the perspective of resource utilization, there are two main reasons for using multithreading: IO blocking and multi-CPU.
The number of threads is not as many as possible, so how many threads should be started?
There is a reference formula:
Number of startup threads = (task execution time / (task execution time-IO wait time)) * number of CPU cores
The optimal number of startup threads is proportional to the number of CPU cores and inversely proportional to IO blocking time. If all tasks are CPU computing tasks, the maximum number of threads should not exceed the number of CPU cores, because no matter how many threads are started, CPU will not have time to schedule; on the contrary, if the task needs to wait for disk operation and network response, then many startup threads will help the task and penalty bet, and improve system throughput.
Thread safety issues
Design objects as stateless objects
Working with local object
Use locks when accessing resources concurrently
Resource reuse
The creation and destruction of expensive system resources, such as database connections, network communication connections, threads, complex objects, etc., should be minimized. From a programming point of view, there are two main modes of resource reuse: singleton mode and object pool.
Data structure
According to the specific scenario, choose the appropriate data structure.
Garbage collection
If the Web application runs in an environment with garbage collection capabilities such as JVM, garbage collection may have a significant impact on the performance characteristics of the system. The immediate garbage collection mechanism helps with program optimization and parameter tuning, as well as writing memory-safe code.
4. Storage performance optimization 4.1. Mechanical keyboard and solid state hard drive
Consider using solid state drives instead of mechanical keyboards because they can read and write faster.
4.2. B+ number and LSM Tree
The database index of traditional relational database generally uses the B + tree structure of two-level index, and the tree has no more than three layers. Therefore, it may take five disk accesses to update a record (three disk accesses to get the data index and row ID, followed by one data file read operation and one data file write operation).
Because the disk access is random, the performance of the traditional mechanical keyboard is poor when the data is accessed randomly, and each data access needs to access the disk several times to affect the data access performance.
Many indexes in Nosql databases use LSM tree as the main data structure. The LSM tree can be regarded as an N-order merge tree. Data writes are done in memory. A data update on a LSM tree does not require disk access and is much faster than a B+ tree.
4.3. RAID and HDFS
HDFS (distributed file system) is more favored by large websites. It can cooperate with the MapReduce concurrent computing task framework for big data processing, and can access all disks concurrently on the entire cluster without RAID support.
After reading this, the article "what is the method of high-performance system architecture design behind a large website" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.