Private food Lecture 3: high load
Recently, many people are increasing concurrency and high load. This problem suddenly becomes very mysterious and has become a question that many large companies must ask you,
If you tell him that I have not done too much concurrency, he immediately asks you, then tell me how many PV projects you have done, or directly ask you this.
When you hear this problem, you are very ashamed. I have done a maximum of 100 PVS, and the employees of those large companies are just a few thousand yuan away,
This problem is so serious that the employees of a small company are inferior to those of a large company.
Yes. Have you ever wondered whether a person's judgment on PV and high concurrency depends on the hardware platform that follows? If there are thousands of machines,
Are you proud to have made some PVS? Can you build such a hardware platform smoothly and control various technical details?
This depends on the individual's ability. If an employee of a small company gives him an environment, he will also learn about this series of problems. In fact, this problem
Very extreme. People who build the system architecture will definitely make the system very flexible, so that the people who use it can achieve the maximum performance with the least operation, while those who use the program architecture
You must find a way to avoid various situations in the program architecture. Finally, you can implement various deployments by modifying the configuration file.
There is no chance to know these differences, so no matter what company you work for, it is hard to remember what complicated hardware knowledge is, unless you dig carefully.
I am now working on a hardware architecture diagram. First, I declare that I have not performed PV of tens of millions.
How to deal with high concurrency?
This question is too subtle. If you don't talk about any requirements, you can directly throw it to you. If you don't define the detailed scope of use, no matter how you answer it, it's wrong.
In fact, when you go to an interview, you will also throw such a question. Your goal is not to let him give you a satisfactory answer, and you have another idea.
On the homepage, no matter how good the performance of a single machine is, it cannot resist the PV of its domicile. In web development, concurrency must come from high PV, or in details, the PV of a single machine is high, high concurrency,
In this case, no matter how optimized you are on a single machine, it is impossible to solve the problem. Because of the high concurrency, you have not told you what the bottleneck is and have not said to any extent, what we can do is
Add servers, and then load balancing. This is the first point. Server Load balancer is used in only two cases: hardware, software, and hardware devices.
Software Solution, using nginx, DNS carousel, or other. This depends entirely on the focus.
What should I do now besides the problems such as session and cache?
Yes, it's terrible. In this way, we add a cache server to solve this problem and store the shared information on the cache server.
We are now looking at the perfect structure. We can expand it infinitely. We can use a lot of open-source software to solve the file synchronization problem. Or write a socket service for file transmission.
Now we need to further optimize it, because if we find that such a platform cannot be expanded infinitely, the cache server and Server Load balancer server will become the bottleneck in the future. What should we do?
At this time, we have raised the question of domain name planning, that is, a domain name under such a group of server support, constitute a network system, we further ease the pressure.
What should I do if there is a problem? Most companies use cookie encryption to solve this problem. What should we do with our database?
What if some data is shared?
We use the same situation to achieve database read/write splitting. We also use data clusters for database connection.
About how to synchronize data, Mysql itself has this function, how to configure it, and how to complement each other. There are many solutions under Baidu.
For the read/write splitting, we can directly separate it in the program. For the splitting solution, see my database encapsulation class.
In addition, we can use the MySQL proxy and the language room Lua to implement this function.
We have done this. What's the problem?
In fact, our system has a lot of access, images, JS files, CSS files, and these files are not modified frequently. Therefore, we need to add a file server. At the same time, reverse Proxy is used to solve the problem that users frequently request the same public file.
Many people have asked me, but you have said one of the most fundamental questions you have asked. Static, static, can greatly improve the server load performance, however, not all servers can use small pages, the number of reads, and so on. We use static
We can use ajax to dynamically extract some other data. In fact, static, this problem is very serious, because there are many solutions, one is to generate directly, and the other is to use the 404 error, that is, the file requested by the user does not exist.
You can only talk about it based on your specific usage.
In addition, there are some more special problems. Now there are a lot of web games, and there are many frequent interactions in them. How can this problem be solved?
Most of the current solutions are implemented by using flash persistent connections and Ajax Round Robin, that is, converting to PV and concurrency. Therefore, the selection of HTTP servers is involved. These are more specific.
Another aspect of optimization is: first, whether your program is optimal, whether the program design structure is optimal, whether user requests can increase the cache, and user changes to data, how much problems can be tolerated, and so on.
Therefore, user requirements are the root of everything. PV is actually not terrible. There are so many effective solutions.
Summary:
1. Rigorous Requirement Analysis
2. Measure the user experience.
3. Domain Name Planning
4. Rationality of Program Design
5. Cache Usage
6. Resolving PV pressure
7. hardware platform scalability
In fact, these do not mention a lot of details, because rich companies can use CDN, multi-line servers, and so on, rich practices.
There are also many solutions for server backup and monitoring, which are more open-source and paid.
About the establishment of the log server, and so on.