Classic interview questions: What might be the reason why users report that the website you develop is slow to visit?

Problem scenario: A user reported to you that the website you developed has a slow access speed, but the user visits other websites normally. Analyze the reason, what tools are there to analyze the reason, and how to solve the problem?

I encountered this problem twice in recent interviews. I came back to ask a senior who is doing operation and maintenance. After listening to his explanation, I found that this problem can involve a lot of knowledge. It is very comprehensive and a good topic, but in fact, this problem is not lucky. Dimension, but developers naturally understand the better. Combined with this senior's detailed explanation, I sorted out some points involved in this issue.

1. For this topic, we can simply understand that it is a problem on the server side, rather than a problem on the client side (the user network is not good, including domain name server resolution, etc.). Of course, the interviewer must test your client knowledge, such as domain name resolution. , There are also a lot of knowledge points that can be tested, but for this issue alone, more emphasis is on the knowledge points on the server side. Let's analyze the possible reasons one by one:

(1) Possible cause 1: The server outlet bandwidth is not enough. This is a very common bottleneck. On the one hand, it may be that the export bandwidth of the server purchased by itself is very small (the bandwidth purchased by the enterprise is quite expensive). Once the user visits come up and the concurrency is large, the export bandwidth equally distributed to users will naturally be smaller, so some The user's access speed will drop a lot. The other is the bandwidth reduction caused by cross-operator networks. For example, many companies' websites (servers) are placed on the telecom network, and if the user is connected to the Great Wall or Unicom broadband, the network transmission between operators There are restrictions during docking, which may result in a reduction in bandwidth.

(2) Possible reason two: The server load is too heavy and too busy, for example, the CPU and memory are exhausted. This is easy to understand and does not expand.

(3) Possible reason three: The development code of the website is not well written, for example, the mysql statement is not optimized, which makes the reading and writing of the database quite time-consuming.

(4) Possible reason four: the bottleneck of the database is also a very common bottleneck. This can be explained together with the third reason above. When our database becomes larger and larger, for example, many G and many T are so big, then the read and write to the database will become quite slow, index optimization can improve some efficiency, but the database is already so large, if every time All queries are performed globally for such a large database, which is naturally slow. This is easy to understand if you have learned the database.

2. For the above possible reasons, what methods and tools are there to detect?

(1) How to locate the problem when a certain user reported that the website visit was slow. First, you open the website yourself to see if there are any problems reported by users. If you have no problems with access here, it may be the problem on the user side. This is to determine whether it is the user’s problem or yourself. For example, server or website problems.

(2) If you find that it is really a problem with your own server or website, you can use the debugging function of the browser (generally browsers will have), debug the network to see the speed of various data loading, which one can consume how much time you can see Then, which piece of data is taking too much time, is the image loading too slow, or some data loading can’t be found for a long time.

(3) Then according to the load of the server, you can check the consumption of the server hardware (network bandwidth, CPU, memory). In terms of bandwidth, check the traffic monitoring to see if it has reached the peak and the bandwidth is not enough. If the company buys its own website server, you need to build your own monitoring environment; if you use Alibaba Cloud and Tencent Cloud, then these platforms The side will provide various aspects of monitoring such as CPU, bandwidth, etc., which can be seen in the background.

(4) If you find that the hardware resource consumption is not high, and the hardware resources are relatively abundant, then you have to see if it is a program problem. This can be found by checking logs, such as PHP logs, Apache logs, mysql logs, etc. error logs, especially if MySQL has a slow query log function, you can see if a certain mysql statement is particularly slow, if a certain statement It takes too long, then this sentence is likely to be problematic.

(5) As for the database mentioned is too large, this can be seen directly, for example, the file size of a table has become extremely large.

3. For the above problems, what are the solutions and optimization methods?

(1) The issue of export bandwidth is very simple. Add bandwidth and buy more bandwidth if you have money. It is very simple.

(2) mysql statement optimization, developer responsibility.

(3) The database is too large. In order to read and write speed, "dismantle the table" and "dismantle the database" is to split the data table or database.

(4) The above demolition and demolition of tables are done for the database is too large, generally there will be other optimization methods before this, such as mysql master-slave replication, a master server is dedicated to writing, and then other slaves The server is used for reading, and will be synchronized to other reading servers after writing. For example, Ali’s Double Eleven event did not know how many tens of thousands of servers were used together.

(6) There is also a non-relational database that has been used more in recent years. It uses a caching mechanism. It caches data in the memory. Users access data directly from the memory. The reading speed is faster than reading from the disk. It's much faster, and it also has a key-value reading mechanism, which I didn't understand after listening to the senior brother.

(7) CDN (content-delivery-network: content delivery network), eggs are placed in multiple baskets, and data is placed closer to the user (for example, some static files on the website such as pictures or js scripts), and users visit When it is judged that the IP source is Guangzhou, it will be resolved to the server in Guangzhou through smart DNS, and the data will be obtained directly from the basket in Guangzhou, and the speed will be faster. There is a concept of static data and dynamic data. For example, pictures and some js files are generally unchanged, so their images can be distributed across the country to speed up, and some data needs to be dynamically generated in the background of the website. You need to go to the server where the website is located to generate and get it. This issue involves the display of two kinds of data, which is handled by the browser. At the same time, asynchronous loading technologies such as the front-end Ajax technology and asynchronous request data can delay the loading of these dynamic data. This is not well understood by myself and may not be well expressed. The front-end developers should understand better.

(8) None of the above mentioned the optimization of the architecture. If the website cannot be supported, is it because the architecture of the website cannot be adapted anymore. For example, if a small blog uses the same server for the database server and web server, then all loads are on the same On the server. But the traffic can’t hold up, you have to add a server, you have to optimize the architecture, such as clustering on the database, and clustering on the web server, such as a web server cluster, add a load balancer in front of the server , Load balancing is specifically responsible for distribution and evenly distribute user requests to each server.

 

     The content is a bit too much. After the brother gave it to me, it was difficult for him to digest for a while, and there were many things that he hadn't touched yet or only had one concept. As a professional operation and maintenance personnel, my brother has a wide range of knowledge.

Guess you like

Origin blog.csdn.net/orzMrXu/article/details/102527316