Suppose that the registration app is purchased from the supplier with 5W RMBs, and a large number of candidates rush in on the day of registration, and the number of concurrent applications soars to 30W +, resulting in system downtime and denial of service, which makes candidates unable to register, then can 5W RMBs support 30W + concurrent applications?
However, for us, we might as well raise the problem to an angle: “how to maximize the server concurrency capability in the limited resources.”. Suppose you are a technical director, how would you design and build a project with a large amount of concurrency?
First of all, we can give a general idea of this project. From the above description, it is not difficult to see that the bottleneck of this project is “concurrent write” rather than “read”. Therefore, we can incline to “write” in terms of resource allocation. Here I write all the data in redis. In addition, we also need to try our best to migrate the read operation of Mysql to redis. The work done by MySQL is more inclined to some conventional non concurrent read and write operations.
When the user requests it, the load balancer loads it to each server
★My PHP learning community “click”The management has sorted out some materials, bat and other first-line large factories’ advanced knowledge systems are ready (relevant learning materials and written questions) and not limited to: distributed architecture, high scalability, high performance, high concurrency, server performance tuning, tp6, laravel, yii2, redis, swoole, swoft, Kafka, MySQL optimization, shell script, docker, micro service Nginx and other knowledge points, advanced dry goods need can be free to share with you
This is a picture fromsymfonyPressure test data, using 1 CPU, 4 GB and PHP 7 configuration.
The data in the figure above comes from the official website of swoole. With the implementation of our actual business logic, we can find that when we are using the resident memory startup mode, three lower configuration servers can solve the above problem that can only be solved by 16.
In fact, many people will understand after contacting the back-end for a certain period of time that the bottleneck of many Internet projects is more concentrated on the database I / O, and there is no particularly big gap between different languages. Including the widely criticized php-fpm startup mode, you can also use spool and other ways to replace. Therefore, in this project, we will focus more on the database. We can try to use redis to solve this problem. Of course, in the specific code, we also need to prepare a certain number of data connection pools in advance. In addition, although mongodb is much faster than MySQL in the same configuration, it still has obvious shortcomings compared with redis.
In fact, registration and login should be divided into two parts. They correspond to “write” and “read” respectively. In the case of high concurrency, using MySQL directly, as you expect, will explode. Therefore, we can cache user data to redis during the whole project construction process The problem of “write”: when the number of users is not clear and the amount of concurrency is large, I prefer not to store user data directly. We can design a switch or threshold to set the user’s warehousing mode. When the concurrency is large, we can use MQ to asynchronously let the user log in, but normally the user can log in normally.
Because the project is not our common second kill, and needs immediate notice, so it greatly reduces the difficulty of our project design. The function of submitting forms is similar to registration. We can store data asynchronously and then audit it in the background.
Other things like whether CDN and MySQL need to be master-slave will not be repeated, depending on the actual situation. Theoretically, if we use php-fpm, it will cost about 19000 yuan / month to solve this problem. When we use spool, it will cost about 4500 yuan / month. We don’t advocate spool here. What we want to show is that when we face large concurrent projects, especially when the business logic is relatively complex, we can solve the problem better by using resident memory, which has nothing to do with the language. Finally, it should be noted that the above is only a theoretical stage, and the actual data need to be further tested. The material of the article comes from the Internet. If there is something wrong with it, please point out.
If you like my article and want to exchange and study with more senior developers, you can get more technical consultation and guidance related to the interview of large factories. Welcome to join our group-Click here 。